Skip to contentSkip to conversation

cifs: define inode-level cache object and register them

RFC PATCH In review Suresh Jayaraman 7 participants 12 messages Jun 22, 2010 – Jun 27, 2010 6 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 6/10 cifs: define inode-level cache object and register them

Define inode-level data storage objects (managed by cifsInodeInfo structs). Each inode-level object is created in a super-block level object and is itself a data storage object in to which pages from the inode are stored.

The inode object is keyed by UniqueId. The coherency data being used is LastWriteTime and the file size.

---
 fs/cifs/cache.c    |   80 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/cifs/cifsfs.c   |    7 ++++
 fs/cifs/cifsglob.h |    3 +
 fs/cifs/file.c     |    6 +++
 fs/cifs/fscache.c  |   68 +++++++++++++++++++++++++++++++++++++++++++++
 fs/cifs/fscache.h  |   12 +++++++
 fs/cifs/inode.c    |    4 ++
 7 files changed, 180 insertions(+)
fs/cifs/cache.c +80 -0
Index: cifs-2.6/fs/cifs/cache.c
===================================================================
@@ -138,3 +138,83 @@ const struct fscache_cookie_def cifs_fsc
 	.get_key = cifs_super_get_key,
 };
 
+/*
+ * Auxiliary data attached to CIFS inode within the cache
+ */
+struct cifs_fscache_inode_auxdata {
+	struct timespec	last_write_time;
+	loff_t		size;
+};
+
+static uint16_t cifs_fscache_inode_get_key(const void *cookie_netfs_data,
+					   void *buffer, uint16_t maxbuf)
+{
+	const struct cifsInodeInfo *cifsi = cookie_netfs_data;
+	uint16_t keylen;
+
+	/* use the UniqueId as the key */
+	keylen = sizeof(cifsi->uniqueid);
+	if (keylen > maxbuf)
+		keylen = 0;
+	else
+		memcpy(buffer, &cifsi->uniqueid, keylen);
+
+	return keylen;
+}
+
+static void
+cifs_fscache_inode_get_attr(const void *cookie_netfs_data, uint64_t *size)
+{
+	const struct cifsInodeInfo *cifsi = cookie_netfs_data;
+
+	*size = cifsi->vfs_inode.i_size;
+}
+
+static uint16_t
+cifs_fscache_inode_get_aux(const void *cookie_netfs_data, void *buffer,
+			   uint16_t maxbuf)
+{
+	struct cifs_fscache_inode_auxdata auxdata;
+	const struct cifsInodeInfo *cifsi = cookie_netfs_data;
+
+	memset(&auxdata, 0, sizeof(auxdata));
+	auxdata.size = cifsi->vfs_inode.i_size;
+	auxdata.last_write_time = cifsi->vfs_inode.i_ctime;
+
+	if (maxbuf > sizeof(auxdata))
+		maxbuf = sizeof(auxdata);
+
+	memcpy(buffer, &auxdata, maxbuf);
+
+	return maxbuf;
+}
+
+static enum
+fscache_checkaux cifs_fscache_inode_check_aux(void *cookie_netfs_data,
+					      const void *data,
+					      uint16_t datalen)
+{
+	struct cifs_fscache_inode_auxdata auxdata;
+	struct cifsInodeInfo *cifsi = cookie_netfs_data;
+
+	if (datalen != sizeof(auxdata))
+		return FSCACHE_CHECKAUX_OBSOLETE;
+
+	memset(&auxdata, 0, sizeof(auxdata));
+	auxdata.size = cifsi->vfs_inode.i_size;
+	auxdata.last_write_time = cifsi->vfs_inode.i_ctime;
+
+	if (memcmp(data, &auxdata, datalen) != 0)
+		return FSCACHE_CHECKAUX_OBSOLETE;
+
+	return FSCACHE_CHECKAUX_OKAY;
+}
+
+const struct fscache_cookie_def cifs_fscache_inode_object_def = {
+	.name		= "CIFS.uniqueid",
+	.type		= FSCACHE_COOKIE_TYPE_DATAFILE,
+	.get_key	= cifs_fscache_inode_get_key,
+	.get_attr	= cifs_fscache_inode_get_attr,
+	.get_aux	= cifs_fscache_inode_get_aux,
+	.check_aux	= cifs_fscache_inode_check_aux,
+};
fs/cifs/cifsfs.c +7 -0
Index: cifs-2.6/fs/cifs/cifsfs.c
===================================================================
@@ -330,6 +330,12 @@ cifs_destroy_inode(struct inode *inode)
 }
 
 static void
+cifs_clear_inode(struct inode *inode)
+{
+	cifs_fscache_release_inode_cookie(inode);
+}
+
+static void
 cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
 {
 	seq_printf(s, ",addr=");
@@ -490,6 +496,7 @@ static const struct super_operations cif
 	.alloc_inode = cifs_alloc_inode,
 	.destroy_inode = cifs_destroy_inode,
 	.drop_inode	= cifs_drop_inode,
+	.clear_inode	= cifs_clear_inode,
 /*	.delete_inode	= cifs_delete_inode,  */  /* Do not need above
 	function unless later we add lazy close of inodes or unless the
 	kernel forgets to call us with the same number of releases (closes)
fs/cifs/cifsglob.h +3 -0
Index: cifs-2.6/fs/cifs/cifsglob.h
===================================================================
@@ -407,6 +407,9 @@ struct cifsInodeInfo {
 	bool invalid_mapping:1;		/* pagecache is invalid */
 	u64  server_eof;		/* current file size on server */
 	u64  uniqueid;			/* server inode number */
+#ifdef CONFIG_CIFS_FSCACHE
+	struct fscache_cookie *fscache;
+#endif
 	struct inode vfs_inode;
 };
 
fs/cifs/file.c +6 -0
Index: cifs-2.6/fs/cifs/file.c
===================================================================
@@ -40,6 +40,7 @@
 #include "cifs_unicode.h"
 #include "cifs_debug.h"
 #include "cifs_fs_sb.h"
+#include "fscache.h"
 
 static inline int cifs_convert_flags(unsigned int flags)
 {
@@ -282,6 +283,9 @@ int cifs_open(struct inode *inode, struc
 				CIFSSMBClose(xid, tcon, netfid);
 				rc = -ENOMEM;
 			}
+
+			cifs_fscache_set_inode_cookie(inode, file);
+
 			goto out;
 		} else if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
 			if (tcon->ses->serverNOS)
@@ -373,6 +377,8 @@ int cifs_open(struct inode *inode, struc
 		goto out;
 	}
 
+	cifs_fscache_set_inode_cookie(inode, file);
+
 	if (oplock & CIFS_CREATE_ACTION) {
 		/* time to set mode which we can not set earlier due to
 		   problems creating new read-only files */
fs/cifs/fscache.c +68 -0

71 lines not on this page · raw message

fs/cifs/fscache.h +12 -0
Index: cifs-2.6/fs/cifs/fscache.h
===================================================================
@@ -29,6 +29,8 @@
 extern struct fscache_netfs cifs_fscache_netfs;
 extern const struct fscache_cookie_def cifs_fscache_server_index_def;
 extern const struct fscache_cookie_def cifs_fscache_super_index_def;
+extern const struct fscache_cookie_def cifs_fscache_inode_object_def;
+
 
 extern int cifs_fscache_register(void);
 extern void cifs_fscache_unregister(void);
@@ -41,6 +43,10 @@ extern void cifs_fscache_release_client_
 extern void cifs_fscache_get_super_cookie(struct cifsTconInfo *);
 extern void cifs_fscache_release_super_cookie(struct cifsTconInfo *);
 
+extern void cifs_fscache_release_inode_cookie(struct inode *);
+extern void cifs_fscache_set_inode_cookie(struct inode *, struct file *);
+extern void cifs_fscache_reset_inode_cookie(struct inode *);
+
 #else /* CONFIG_CIFS_FSCACHE */
 static inline int cifs_fscache_register(void) { return 0; }
 static inline void cifs_fscache_unregister(void) {}
@@ -53,6 +59,12 @@ static inline void cifs_fscache_get_supe
 static inline void
 cifs_fscache_release_super_cookie(struct cifsTconInfo *tcon) {}
 
+static inline void cifs_fscache_release_inode_cookie(struct inode *inode) {}
+static inline void cifs_fscache_set_inode_cookie(struct inode *inode,
+			struct file *filp) {}
+static inline void cifs_fscache_reset_inode_cookie(struct inode *inode) {}
+
+
 #endif /* CONFIG_CIFS_FSCACHE */
 
 #endif /* _CIFS_FSCACHE_H */
fs/cifs/inode.c +4 -0
Index: cifs-2.6/fs/cifs/inode.c
===================================================================
@@ -29,6 +29,7 @@
 #include "cifsproto.h"
 #include "cifs_debug.h"
 #include "cifs_fs_sb.h"
+#include "fscache.h"
 
 
 static void cifs_set_ops(struct inode *inode, const bool is_dfs_referral)
@@ -776,6 +777,8 @@ retry_iget5_locked:
 			inode->i_flags |= S_NOATIME | S_NOCMTIME;
 		if (inode->i_state & I_NEW) {
 			inode->i_ino = hash;
+			/* initialize per-inode cache cookie pointer */
+			CIFS_I(inode)->fscache = NULL;
 			unlock_new_inode(inode);
 		}
 	}
@@ -1568,6 +1571,7 @@ cifs_invalidate_mapping(struct inode *in
 			cifs_i->write_behind_rc = rc;
 	}
 	invalidate_remote_inode(inode);
+	cifs_fscache_reset_inode_cookie(inode);
 }
 
 int cifs_revalidate_file(struct file *filp)

A message that is not in the archive (sent off-list or not yet received): 1277220214-3597-1-git-send-email-sjayaraman-l3A5Bk7waGM@public.gmane.org

#2 lore raw
Quoted 6 lines · Suresh Jayaraman

Define inode-level data storage objects (managed by cifsInodeInfo structs). Each inode-level object is created in a super-block level object and is itself a data storage object in to which pages from the inode are stored.

The inode object is keyed by UniqueId. The coherency data being used is LastWriteTime and the file size.

Isn't there a file creation time too?

I take it you don't support caching on files that are open for writing at this time?

David

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 10 lines · David Howells
Quoted 6 lines · Suresh Jayaraman

Define inode-level data storage objects (managed by cifsInodeInfo structs). Each inode-level object is created in a super-block level object and is itself a data storage object in to which pages from the inode are stored.

The inode object is keyed by UniqueId. The coherency data being used is LastWriteTime and the file size.

Isn't there a file creation time too?

I think the creation time is currently being ignored as we won't be able to accomodate in POSIX stat struct.

Quoted 3 lines

I take it you don't support caching on files that are open for writing at this time?

Yes.

Signature · 1 line
Suresh Jayaraman

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw
Quoted 2 lines · Suresh Jayaraman

I think the creation time is currently being ignored as we won't be able to accomodate in POSIX stat struct.

The FS-Cache interface doesn't use the POSIX stat struct, but it could be really useful to save it and use it for cache coherency inside the kernel.

Out of interest, what does Samba do when it comes to generating a creation time for UNIX where one does not exist?

David

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw
Quoted 11 lines · On Fri, 25 Jun 2010 13:55:49 +0100 David Howells…
Quoted 2 lines · Suresh Jayaraman

I think the creation time is currently being ignored as we won't be able to accomodate in POSIX stat struct.

The FS-Cache interface doesn't use the POSIX stat struct, but it could be really useful to save it and use it for cache coherency inside the kernel.

Out of interest, what does Samba do when it comes to generating a creation time for UNIX where one does not exist?

(cc'ing samba-technical since we're talking about the create time)

Looks like it mostly uses the ctime. IMO, the mtime would be a better choice since it changes less frequently, but I don't guess that it matters very much.

I have a few patches that make the cifs_iget code do more stringent checks. One of those makes it use the create time like an i_generation field to guard against matching inodes that have the same number but that have undergone a delete/create cycle. They need a bit more testing but I'm planning to post them in time for 2.6.36.

Because of how samba generates this number, it could be somewhat problematic to do this. What may save us though is that Linux<->Samba mostly uses unix extensions unless someone has specifically disabled them on either end. The unix extension calls don't generally send any sort of create time field, so we can't rely on it in those codepaths anyway.

Signature · 1 line
Jeff Layton <[email protected]>
#9 lore raw
Quoted 3 lines · Jeff Layton

Looks like it mostly uses the ctime. IMO, the mtime would be a better choice since it changes less frequently, but I don't guess that it matters very much.

I'd've thought mtime changes more frequently since that's altered when data is written. ctime is changed when attributes are changed.

Note that Ext4 appears to have a file creation time field in its inode (struct ext4_inode::i_crtime[_extra]). Can Samba be made to use that?

David

#10 lore raw
Quoted 9 lines · On Fri, 25 Jun 2010 22:46:38 +0100 David Howells <[email protected]> wrote:
Quoted 3 lines · Jeff Layton

Looks like it mostly uses the ctime. IMO, the mtime would be a better choice since it changes less frequently, but I don't guess that it matters very much.

I'd've thought mtime changes more frequently since that's altered when data is written. ctime is changed when attributes are changed.

IIUC, updating mtime for a write is also an attribute change, and that affects ctime. According to the stat(2) manpage:

The field st_ctime is changed by writing or by setting inode informa- tion (i.e., owner, group, link count, mode, etc.).

Quoted 3 lines

Note that Ext4 appears to have a file creation time field in its inode (struct ext4_inode::i_crtime[_extra]). Can Samba be made to use that?

Is it exposed to userspace in any (standard) way? It would be handy to have that. While we're wishing...it might also be nice to have a standard way to get at the i_generation from userspace too.

Signature · 1 line
Jeff Layton <[email protected]>
#11 lore raw
Quoted 20 lines · Jeff Layton
Quoted 9 lines · On Fri, 25 Jun 2010 22:46:38 +0100 David Howells <[email protected]> wrote:
Quoted 3 lines · Jeff Layton

Looks like it mostly uses the ctime. IMO, the mtime would be a better choice since it changes less frequently, but I don't guess that it matters very much.

I'd've thought mtime changes more frequently since that's altered when data is written.  ctime is changed when attributes are changed.

IIUC, updating mtime for a write is also an attribute change, and that affects ctime. According to the stat(2) manpage:

      The field st_ctime is changed by writing or by setting  inode  informa- tion (i.e., owner, group, link count, mode, etc.).

Quoted 8 lines
Quoted 3 lines

Note that Ext4 appears to have a file creation time field in its inode (struct ext4_inode::i_crtime[_extra]).  Can Samba be made to use that?

Is it exposed to userspace in any (standard) way? It would be handy to have that. While we're wishing...it might also be nice to have a standard way to get at the i_generation from userspace too.

Yes - I have talked with MingMing and Aneesh about those (NFS may someday be able to use those too).  An obstacle in the past had been that samba server stores its own fake creation time in an ndr encoded xattr which complicates things.

MingMing/Annesh -
Xattr or other way to get at birth time?

--
Thanks,

Steve

#12 lore raw

Steve French <[email protected]> wrote on 06/25/2010 04:05:30 PM:

Quoted 15 lines

Steve French <[email protected]>
06/25/2010 04:05 PM

To

Jeff Layton <[email protected]>, "Aneesh Kumar K.V" <[email protected]>, Mingming Cao/Beaverton/IBM@IBMUS

cc

David Howells <[email protected]>, Suresh Jayaraman <[email protected]>, [email protected], linux- [email protected], [email protected], samba- [email protected], Jeff Layton <[email protected]>

Quoted 13 lines

Subject

Re: [RFC][PATCH 06/10] cifs: define inode-level cache object and register them

Quoted 7 lines · Jeff Layton
Quoted 3 lines · On Fri, 25 Jun 2010 22:46:38 +0100 David Howells <[email protected]> wrote:
Quoted 1 line · Jeff Layton

Looks like it mostly uses the ctime. IMO, the mtime would be a

better

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

choice since it changes less frequently, but I don't guess that it matters very much.

I'd've thought mtime changes more frequently since that's

altered when data is

Quoted 11 lines
Quoted 7 lines
Quoted 2 lines

written.  ctime is changed when attributes are changed.

IIUC, updating mtime for a write is also an attribute change, and that affects ctime. According to the stat(2) manpage:

      The field st_ctime is changed by writing or by setting

 inode  informa-

Quoted 3 lines

      tion (i.e., owner, group, link count, mode, etc.).

Quoted 1 line

Note that Ext4 appears to have a file creation time field in its

inode

Quoted 1 line
Quoted 1 line
Quoted 1 line

(struct ext4_inode::i_crtime[_extra]).  Can Samba be made to use

that?

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Is it exposed to userspace in any (standard) way? It would be handy to have that. While we're wishing...it might also be nice to have a standard way to get at the i_generation from userspace too.

Quoted 9 lines

Yes - I have talked with MingMing and Aneesh about those (NFS may someday be able to use those too).  An obstacle in the past had been that samba server stores its own fake creation time in an ndr encoded xattr which complicates things.

MingMing/Annesh -
Xattr or other way to get at birth time?

Not yet,
The ext4 file creation time only accesable from the kernel at the moment.
There were discussion
to make this information avaliable via xattr before, but was rejected, since most people
agree that making this info avalibele via stat() is more standard. However modifying stat() would imply
big interface change. thus no action has been taken yet.

Quoted 4 lines

--
Thanks,

Steve

#13 lore raw
Quoted 69 lines · Mingming Cao

Steve French <[email protected]> wrote on 06/25/2010 04:05:30 PM:

Quoted 15 lines

Steve French <[email protected]>
06/25/2010 04:05 PM

To

Jeff Layton <[email protected]>, "Aneesh Kumar K.V" <[email protected]>, Mingming Cao/Beaverton/IBM@IBMUS

cc

David Howells <[email protected]>, Suresh Jayaraman <[email protected]>, [email protected], linux- [email protected], [email protected], samba- [email protected], Jeff Layton <[email protected]>

Quoted 13 lines

Subject

Re: [RFC][PATCH 06/10] cifs: define inode-level cache object and register them

Quoted 7 lines · Jeff Layton
Quoted 3 lines · On Fri, 25 Jun 2010 22:46:38 +0100 David Howells <[email protected]> wrote:
Quoted 1 line · Jeff Layton

Looks like it mostly uses the ctime. IMO, the mtime would be a

better

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

choice since it changes less frequently, but I don't guess that it matters very much.

I'd've thought mtime changes more frequently since that's

altered when data is

Quoted 11 lines
Quoted 7 lines
Quoted 2 lines

written.  ctime is changed when attributes are changed.

IIUC, updating mtime for a write is also an attribute change, and that affects ctime. According to the stat(2) manpage:

      The field st_ctime is changed by writing or by setting

 inode  informa-

Quoted 3 lines

      tion (i.e., owner, group, link count, mode, etc.).

Quoted 1 line

Note that Ext4 appears to have a file creation time field in its

inode

Quoted 1 line
Quoted 1 line
Quoted 1 line

(struct ext4_inode::i_crtime[_extra]).  Can Samba be made to use

that?

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Is it exposed to userspace in any (standard) way? It would be handy to have that. While we're wishing...it might also be nice to have a standard way to get at the i_generation from userspace too.

Quoted 9 lines

Yes - I have talked with MingMing and Aneesh about those (NFS may someday be able to use those too).  An obstacle in the past had been that samba server stores its own fake creation time in an ndr encoded xattr which complicates things.

MingMing/Annesh -
Xattr or other way to get at birth time?

Quoted 8 lines

Not yet,
The ext4 file creation time only accesable from the kernel at the moment.
There were discussion
to make this information avaliable via xattr before, but was rejected, since most people
agree that making this info avalibele via stat() is more standard. However modifying stat() would imply
big interface change. thus no action has been taken yet.

NFS ganesha pNFS also had a requirement for getting i_generation and inode number in userspace. So may be we should now look at updating stat or add a variant syscall that include i_generation and create time in the return value

-aneesh

A message that is not in the archive (sent off-list or not yet received): [email protected]

#15 lore raw
Quoted 4 lines · Aneesh Kumar K. V

NFS ganesha pNFS also had a requirement for getting i_generation and inode number in userspace. So may be we should now look at updating stat or add a variant syscall that include i_generation and create time in the return value

What's missing in knfsd that you feel the sudden urge to move backwards to a userspace nfsd (one with a horribly crappy codebase, too).

A message that is not in the archive (sent off-list or not yet received): 20100625182651.36800d06-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#17 lore raw
Quoted 2 lines · Jeff Layton

IIUC, updating mtime for a write is also an attribute change, and that affects ctime. According to the stat(2) manpage:

You're right. Okay, ctime is the more frequently changed.

Quoted 6 lines
Quoted 2 lines

Note that Ext4 appears to have a file creation time field in its inode (struct ext4_inode::i_crtime[_extra]). Can Samba be made to use that?

Is it exposed to userspace in any (standard) way? It would be handy to have that. While we're wishing...it might also be nice to have a standard way to get at the i_generation from userspace too.

Not at present, but it's something that could be exported by ioctl() or getxattr().

David