Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1391088 > unrolled thread

[RFC][PATCH 0/6] Enhanced file stat system call

Started byDavid Howells <dhowells@redhat.com>
First post2016-04-29 15:00 +0200
Last post2016-05-09 15:50 +0200
Articles 20 on this page of 43 — 11 participants

Back to article view | Back to linux.kernel


Contents

  [RFC][PATCH 0/6] Enhanced file stat system call David Howells <dhowells@redhat.com> - 2016-04-29 15:00 +0200
    [PATCH 4/6] statx: NFS: Return enhanced file attributes David Howells <dhowells@redhat.com> - 2016-04-29 15:00 +0200
      Re: [PATCH 4/6] statx: NFS: Return enhanced file attributes Andreas Dilger <adilger@dilger.ca> - 2016-05-03 00:50 +0200
    [PATCH 6/6] statx: CIFS: Return enhanced attributes David Howells <dhowells@redhat.com> - 2016-04-29 15:00 +0200
    [PATCH 3/6] statx: Ext4: Return enhanced file attributes David Howells <dhowells@redhat.com> - 2016-04-29 15:00 +0200
      Re: [PATCH 3/6] statx: Ext4: Return enhanced file attributes Andreas Dilger <adilger@dilger.ca> - 2016-05-03 00:50 +0200
        Re: [PATCH 3/6] statx: Ext4: Return enhanced file attributes David Howells <dhowells@redhat.com> - 2016-05-03 22:30 +0200
      Re: [PATCH 3/6] statx: Ext4: Return enhanced file attributes Christoph Hellwig <hch@infradead.org> - 2016-05-08 10:40 +0200
    [PATCH 5/6] statx: Make windows attributes available for CIFS,  NTFS and FAT to use David Howells <dhowells@redhat.com> - 2016-04-29 15:10 +0200
      Re: [PATCH 5/6] statx: Make windows attributes available for CIFS, NTFS and FAT to use Andreas Dilger <adilger@dilger.ca> - 2016-05-03 01:00 +0200
        Re: [PATCH 5/6] statx: Make windows attributes available for CIFS, NTFS and FAT to use David Howells <dhowells@redhat.com> - 2016-05-03 22:30 +0200
      Re: [PATCH 5/6] statx: Make windows attributes available for CIFS,  NTFS and FAT to use Christoph Hellwig <hch@infradead.org> - 2016-05-08 10:40 +0200
    [PATCH 2/6] statx: AFS: Return enhanced file attributes David Howells <dhowells@redhat.com> - 2016-04-29 15:20 +0200
    Re: [RFC][PATCH 0/6] Enhanced file stat system call Jeff Layton <jlayton@poochiereds.net> - 2016-04-30 23:10 +0200
    Re: [PATCH 1/6] statx: Add a system call to make enhanced file info available David Howells <dhowells@redhat.com> - 2016-05-03 18:00 +0200
    Re: [RFC][PATCH 0/6] Enhanced file stat system call Arnd Bergmann <arnd@arndb.de> - 2016-05-04 15:50 +0200
      Re: [RFC][PATCH 0/6] Enhanced file stat system call Steve French <smfrench@gmail.com> - 2016-05-06 04:10 +0200
        Re: [RFC][PATCH 0/6] Enhanced file stat system call Arnd Bergmann <arnd@arndb.de> - 2016-05-09 15:10 +0200
    Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available Dave Chinner <david@fromorbit.com> - 2016-05-05 01:00 +0200
      Re: [PATCH 1/6] statx: Add a system call to make enhanced file info available NeilBrown <nfbrown@novell.com> - 2016-05-05 02:20 +0200
        Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available Jeff Layton <jlayton@poochiereds.net> - 2016-05-05 21:50 +0200
          Re: [PATCH 1/6] statx: Add a system call to make enhanced file info available David Howells <dhowells@redhat.com> - 2016-05-05 22:10 +0200
            Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available Dave Chinner <david@fromorbit.com> - 2016-05-06 03:50 +0200
          Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available bfields@fieldses.org (J. Bruce Fields) - 2016-05-06 20:10 +0200
      Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available bfields@fieldses.org (J. Bruce Fields) - 2016-05-06 20:30 +0200
        Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available Dave Chinner <david@fromorbit.com> - 2016-05-09 03:50 +0200
          Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available "J. Bruce Fields" <bfields@fieldses.org> - 2016-05-09 04:50 +0200
    Re: [PATCH 1/6] statx: Add a system call to make enhanced file info available NeilBrown <nfbrown@novell.com> - 2016-05-05 02:00 +0200
    Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available Christoph Hellwig <hch@infradead.org> - 2016-05-08 10:40 +0200
      Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available Jeff Layton <jlayton@poochiereds.net> - 2016-05-09 14:10 +0200
        Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available Christoph Hellwig <hch@infradead.org> - 2016-05-10 09:10 +0200
          Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available Jeff Layton <jlayton@poochiereds.net> - 2016-05-10 15:30 +0200
      Re: [PATCH 1/6] statx: Add a system call to make enhanced file info available David Howells <dhowells@redhat.com> - 2016-05-09 15:00 +0200
        Re: [PATCH 1/6] statx: Add a system call to make enhanced file info available David Howells <dhowells@redhat.com> - 2016-05-09 15:10 +0200
        Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available Trond Myklebust <trondmy@primarydata.com> - 2016-05-09 15:40 +0200
        Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available Christoph Hellwig <hch@infradead.org> - 2016-05-10 09:10 +0200
          Re: [PATCH 1/6] statx: Add a system call to make enhanced file info available David Howells <dhowells@redhat.com> - 2016-05-10 10:30 +0200
            Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available Christoph Hellwig <hch@infradead.org> - 2016-05-12 11:20 +0200
      Re: [PATCH 1/6] statx: Add a system call to make enhanced file info available David Howells <dhowells@redhat.com> - 2016-05-09 15:40 +0200
        Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available Christoph Hellwig <hch@infradead.org> - 2016-05-10 09:10 +0200
          Re: [PATCH 1/6] statx: Add a system call to make enhanced file info available David Howells <dhowells@redhat.com> - 2016-05-10 10:50 +0200
            Re: [PATCH 1/6] statx: Add a system call to make enhanced file info  available Christoph Hellwig <hch@infradead.org> - 2016-05-12 11:20 +0200
      Re: [PATCH 1/6] statx: Add a system call to make enhanced file info available David Howells <dhowells@redhat.com> - 2016-05-09 15:50 +0200

Page 1 of 3  [1] 2 3  Next page →


#1391088 — [RFC][PATCH 0/6] Enhanced file stat system call

FromDavid Howells <dhowells@redhat.com>
Date2016-04-29 15:00 +0200
Subject[RFC][PATCH 0/6] Enhanced file stat system call
Message-ID<rtgbv-69i-7@gated-at.bofh.it>
Implement a new system call to provide enhanced file stats.  The patches can
be found here:

	http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=xstat


===========
DESCRIPTION
===========

The first patch provides this new system call:

	long ret = statx(int dfd,
			 const char *filename,
			 unsigned atflag,
			 unsigned mask,
			 struct statx *buffer);

This is an enhanced file stat function that provides a number of useful
features, in summary:

 (1) More information: creation time, data version number, inode generation
     number and flags.  A subset of these is available through a number of
     filesystems (such as CIFS, NFS, AFS, Ext4 and BTRFS).

 (2) Lightweight stat (AT_NO_ATTR_SYNC): Ask for just those details of
     interest, and allow a network fs to approximate anything not of
     interest, without going to the server.

 (3) Heavyweight stat (AT_FORCE_ATTR_SYNC): Force a network fs to flush
     buffers and go to the server, even if it thinks its cached attributes
     are up to date.

 (4) Allow the filesystem to indicate what it can/cannot provide: A
     filesystem can now say it doesn't support a standard stat feature if
     that isn't available.

 (5) Make the fields a consistent size on all arches, and make them large.

 (6) Can be extended by using more request flags and using up the padding
     space in the statx struct.

Note that no lstat() equivalent is required as that can be implemented
through statx() with atflag == 0.  There is also no fstat() equivalent as
that can be implemented through statx() with filename == NULL and the
relevant fd passed as dfd.


=======
TESTING
=======

A test program is added into samples/statx/ by the first patch.

David
---
David Howells (6):
      statx: Add a system call to make enhanced file info available
      statx: AFS: Return enhanced file attributes
      statx: Ext4: Return enhanced file attributes
      statx: NFS: Return enhanced file attributes
      statx: Make windows attributes available for CIFS, NTFS and FAT to use
      statx: CIFS: Return enhanced attributes


 arch/x86/entry/syscalls/syscall_32.tbl |    1 
 arch/x86/entry/syscalls/syscall_64.tbl |    1 
 fs/afs/inode.c                         |   24 ++-
 fs/cifs/cifsfs.h                       |    4 
 fs/cifs/cifsglob.h                     |    8 +
 fs/cifs/dir.c                          |    2 
 fs/cifs/inode.c                        |  117 +++++++++---
 fs/exportfs/expfs.c                    |    4 
 fs/ext4/ext4.h                         |    2 
 fs/ext4/file.c                         |    2 
 fs/ext4/inode.c                        |   30 +++
 fs/ext4/namei.c                        |    2 
 fs/ext4/symlink.c                      |    2 
 fs/nfs/inode.c                         |   41 ++++
 fs/stat.c                              |  306 +++++++++++++++++++++++++++++---
 include/linux/fs.h                     |    5 -
 include/linux/stat.h                   |   15 +-
 include/linux/syscalls.h               |    4 
 include/uapi/linux/fcntl.h             |    2 
 include/uapi/linux/stat.h              |  135 ++++++++++++++
 samples/Makefile                       |    2 
 samples/statx/Makefile                 |   10 +
 samples/statx/test-statx.c             |  274 +++++++++++++++++++++++++++++
 23 files changed, 910 insertions(+), 83 deletions(-)
 create mode 100644 samples/statx/Makefile
 create mode 100644 samples/statx/test-statx.c

[toc] | [next] | [standalone]


#1391089 — [PATCH 4/6] statx: NFS: Return enhanced file attributes

FromDavid Howells <dhowells@redhat.com>
Date2016-04-29 15:00 +0200
Subject[PATCH 4/6] statx: NFS: Return enhanced file attributes
Message-ID<rtgbv-69i-13@gated-at.bofh.it>
In reply to#1391088
Return enhanced file atrributes from the NFS filesystem.  This includes the
following:

 (1) The change attribute as st_version if NFSv4.

 (2) STATX_INFO_AUTOMOUNT and STATX_INFO_FABRICATED are set on referral or
     submount directories that are automounted upon.  NFS shows one
     directory with a different FSID, but the local filesystem has two: the
     mountpoint directory and the root of the filesystem mounted upon it.

 (3) STATX_INFO_REMOTE is set on files acquired over NFS.

 (4) STATX_IOC_FLAGS is set and if the atime is unavailable on a file,
     st_ioc_flags will have FL_NOATIME_FL set in it.

Furthermore, what nfs_getattr() does can be controlled as follows:

 (1) If AT_NO_ATTR_SYNC is indicated then this will suppress the flushing
     of outstanding writes and the rereading of the inode's attributes with
     the server as detailed below.

 (2) Otherwise:

     (a) If AT_FORCE_ATTR_SYNC is indicated, or mtime, ctime or
     	 data_version (NFSv4 only) are requested then the outstanding
     	 writes will be written to the server first.

     (b) The inode's attributes will be reread from the server:

     	 (i) if AT_FORCE_ATTR_SYNC is indicated;

        (ii) if atime is requested (and atime updating is not suppressed by
     	     a mount flag); or

       (iii) if the cached attributes have expired;

If the inode isn't synchronised, then the cached attributes will be used -
even if expired - without reference to the server.

Example output:

	[root@andromeda ~]# ./samples/statx/test-statx /warthog/
	statx(/warthog/) = 0
	results=37ef
	  Size: 4096            Blocks: 8          IO Block: 1048576  directory
	Device: 00:26           Inode: 2           Links: 122
	Access: (3777/drwxrwxrwx)  Uid:     0   Gid:  4041
	Access: 2015-10-30 16:15:41.730925545+0000
	Modify: 2015-10-07 10:33:19.896108112+0100
	Change: 2015-10-07 10:33:19.896108112+0100
	Data version: 5614e6df35698650h
	Inode flags: 00000000 (-------- -------- -------- --------)
	Information: 00000010 (-------- -------- -------- ---r----)
	IO-blocksize: blksize=1048576

Note that the NFS4 protocol potentially provides a creation time that could
be passed through this interface and system, hidden and archive values that
could be passed as IOC flags.  There is also a backup time that could be
added.

Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/nfs/inode.c |   41 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 7 deletions(-)

diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 738c84a42eb0..8637236bca0c 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -655,12 +655,23 @@ static bool nfs_need_revalidate_inode(struct inode *inode)
 int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
 {
 	struct inode *inode = d_inode(dentry);
-	int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME;
+	bool force_sync = stat->query_flags & AT_FORCE_ATTR_SYNC;
+	bool suppress_sync = stat->query_flags & AT_NO_ATTR_SYNC;
+	bool need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME;
 	int err = 0;
 
 	trace_nfs_getattr_enter(inode);
-	/* Flush out writes to the server in order to update c/mtime.  */
-	if (S_ISREG(inode->i_mode)) {
+
+	if (NFS_SERVER(inode)->nfs_client->rpc_ops->version < 4)
+		stat->request_mask &= ~STATX_VERSION;
+
+	/* Flush out writes to the server in order to update c/mtime or data
+	 * version if the user wants them.
+	 */
+	if (S_ISREG(inode->i_mode) && !suppress_sync &&
+	    (force_sync || (stat->request_mask &
+			    (STATX_MTIME | STATX_CTIME | STATX_VERSION)))
+	    ) {
 		inode_lock(inode);
 		err = nfs_sync_inode(inode);
 		inode_unlock(inode);
@@ -677,11 +688,13 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
 	 *  - NFS never sets MS_NOATIME or MS_NODIRATIME so there is
 	 *    no point in checking those.
 	 */
- 	if ((mnt->mnt_flags & MNT_NOATIME) ||
- 	    ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
-		need_atime = 0;
+	if (!(stat->request_mask & STATX_ATIME) ||
+	    (mnt->mnt_flags & MNT_NOATIME) ||
+	    ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
+		need_atime = false;
 
-	if (need_atime || nfs_need_revalidate_inode(inode)) {
+	if (!suppress_sync &&
+	    (force_sync || need_atime || nfs_need_revalidate_inode(inode))) {
 		struct nfs_server *server = NFS_SERVER(inode);
 
 		if (server->caps & NFS_CAP_READDIRPLUS)
@@ -694,6 +707,20 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
 		if (S_ISDIR(inode->i_mode))
 			stat->blksize = NFS_SERVER(inode)->dtsize;
 	}
+
+	generic_fillattr(inode, stat);
+	stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode));
+
+	if (stat->request_mask & STATX_VERSION) {
+		stat->version = inode->i_version;
+		stat->result_mask |= STATX_VERSION;
+	}
+
+	if (IS_AUTOMOUNT(inode))
+		stat->information |= STATX_INFO_FABRICATED;
+
+	stat->information |= STATX_INFO_REMOTE;
+
 out:
 	trace_nfs_getattr_exit(inode, err);
 	return err;

[toc] | [prev] | [next] | [standalone]


#1392553 — Re: [PATCH 4/6] statx: NFS: Return enhanced file attributes

FromAndreas Dilger <adilger@dilger.ca>
Date2016-05-03 00:50 +0200
SubjectRe: [PATCH 4/6] statx: NFS: Return enhanced file attributes
Message-ID<ruuP8-419-25@gated-at.bofh.it>
In reply to#1391089

[Multipart message — attachments visible in raw view] — view raw

On Apr 29, 2016, at 6:58 AM, David Howells <dhowells@redhat.com> wrote:
> 
> Return enhanced file atrributes from the NFS filesystem.  This includes the
> following:
> 
> (1) The change attribute as st_version if NFSv4.
> 
> (2) STATX_INFO_AUTOMOUNT and STATX_INFO_FABRICATED are set on referral or
>     submount directories that are automounted upon.  NFS shows one
>     directory with a different FSID, but the local filesystem has two: the
>     mountpoint directory and the root of the filesystem mounted upon it.
> 
> (3) STATX_INFO_REMOTE is set on files acquired over NFS.
> 
> (4) STATX_IOC_FLAGS is set and if the atime is unavailable on a file,
>     st_ioc_flags will have FL_NOATIME_FL set in it.

This is not implemented in this patch, and should removed from the commit
message.  The generic_fillattr() change in [1/6] will clear the STATX_ATIME
flag if IS_NOATIME() is true, so maybe that is enough for what you intended?

Cheers, Andreas

> Furthermore, what nfs_getattr() does can be controlled as follows:
> 
> (1) If AT_NO_ATTR_SYNC is indicated then this will suppress the flushing
>     of outstanding writes and the rereading of the inode's attributes with
>     the server as detailed below.
> 
> (2) Otherwise:
> 
>     (a) If AT_FORCE_ATTR_SYNC is indicated, or mtime, ctime or
>     	 data_version (NFSv4 only) are requested then the outstanding
>     	 writes will be written to the server first.
> 
>     (b) The inode's attributes will be reread from the server:
> 
>     	 (i) if AT_FORCE_ATTR_SYNC is indicated;
> 
>        (ii) if atime is requested (and atime updating is not suppressed by
>     	     a mount flag); or
> 
>       (iii) if the cached attributes have expired;
> 
> If the inode isn't synchronised, then the cached attributes will be used -
> even if expired - without reference to the server.
> 
> Example output:
> 
> 	[root@andromeda ~]# ./samples/statx/test-statx /warthog/
> 	statx(/warthog/) = 0
> 	results=37ef
> 	  Size: 4096            Blocks: 8          IO Block: 1048576  directory
> 	Device: 00:26           Inode: 2           Links: 122
> 	Access: (3777/drwxrwxrwx)  Uid:     0   Gid:  4041
> 	Access: 2015-10-30 16:15:41.730925545+0000
> 	Modify: 2015-10-07 10:33:19.896108112+0100
> 	Change: 2015-10-07 10:33:19.896108112+0100
> 	Data version: 5614e6df35698650h
> 	Inode flags: 00000000 (-------- -------- -------- --------)
> 	Information: 00000010 (-------- -------- -------- ---r----)
> 	IO-blocksize: blksize=1048576
> 
> Note that the NFS4 protocol potentially provides a creation time that could
> be passed through this interface and system, hidden and archive values that
> could be passed as IOC flags.  There is also a backup time that could be
> added.
> 
> Signed-off-by: David Howells <dhowells@redhat.com>
> ---
> 
> fs/nfs/inode.c |   41 ++++++++++++++++++++++++++++++++++-------
> 1 file changed, 34 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
> index 738c84a42eb0..8637236bca0c 100644
> --- a/fs/nfs/inode.c
> +++ b/fs/nfs/inode.c
> @@ -655,12 +655,23 @@ static bool nfs_need_revalidate_inode(struct inode *inode)
> int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
> {
> 	struct inode *inode = d_inode(dentry);
> -	int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME;
> +	bool force_sync = stat->query_flags & AT_FORCE_ATTR_SYNC;
> +	bool suppress_sync = stat->query_flags & AT_NO_ATTR_SYNC;
> +	bool need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME;
> 	int err = 0;
> 
> 	trace_nfs_getattr_enter(inode);
> -	/* Flush out writes to the server in order to update c/mtime.  */
> -	if (S_ISREG(inode->i_mode)) {
> +
> +	if (NFS_SERVER(inode)->nfs_client->rpc_ops->version < 4)
> +		stat->request_mask &= ~STATX_VERSION;
> +
> +	/* Flush out writes to the server in order to update c/mtime or data
> +	 * version if the user wants them.
> +	 */
> +	if (S_ISREG(inode->i_mode) && !suppress_sync &&
> +	    (force_sync || (stat->request_mask &
> +			    (STATX_MTIME | STATX_CTIME | STATX_VERSION)))
> +	    ) {
> 		inode_lock(inode);
> 		err = nfs_sync_inode(inode);
> 		inode_unlock(inode);
> @@ -677,11 +688,13 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
> 	 *  - NFS never sets MS_NOATIME or MS_NODIRATIME so there is
> 	 *    no point in checking those.
> 	 */
> - 	if ((mnt->mnt_flags & MNT_NOATIME) ||
> - 	    ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
> -		need_atime = 0;
> +	if (!(stat->request_mask & STATX_ATIME) ||
> +	    (mnt->mnt_flags & MNT_NOATIME) ||
> +	    ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)))
> +		need_atime = false;
> 
> -	if (need_atime || nfs_need_revalidate_inode(inode)) {
> +	if (!suppress_sync &&
> +	    (force_sync || need_atime || nfs_need_revalidate_inode(inode))) {
> 		struct nfs_server *server = NFS_SERVER(inode);
> 
> 		if (server->caps & NFS_CAP_READDIRPLUS)
> @@ -694,6 +707,20 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
> 		if (S_ISDIR(inode->i_mode))
> 			stat->blksize = NFS_SERVER(inode)->dtsize;
> 	}
> +
> +	generic_fillattr(inode, stat);
> +	stat->ino = nfs_compat_user_ino64(NFS_FILEID(inode));
> +
> +	if (stat->request_mask & STATX_VERSION) {
> +		stat->version = inode->i_version;
> +		stat->result_mask |= STATX_VERSION;
> +	}
> +
> +	if (IS_AUTOMOUNT(inode))
> +		stat->information |= STATX_INFO_FABRICATED;
> +
> +	stat->information |= STATX_INFO_REMOTE;
> +
> out:
> 	trace_nfs_getattr_exit(inode, err);
> 	return err;
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


Cheers, Andreas





[toc] | [prev] | [next] | [standalone]


#1391090 — [PATCH 6/6] statx: CIFS: Return enhanced attributes

FromDavid Howells <dhowells@redhat.com>
Date2016-04-29 15:00 +0200
Subject[PATCH 6/6] statx: CIFS: Return enhanced attributes
Message-ID<rtgbw-69i-17@gated-at.bofh.it>
In reply to#1391088
Return enhanced attributes from the CIFS filesystem.  This includes the
following:

 (1) Return the file creation time as btime.  We assume that the creation
     time won't change over the life of the inode.

 (2) Set STATX_INFO_AUTOMOUNT on referral/submount directories.

 (3) Unset STATX_INO if we made up the inode number and didn't get it from
     the server.

 (4) Unset STATX_[UG]ID if we are either returning values passed to mount
     and/or the server doesn't return them.

 (5) Set STATX_WIN_ATTRS and return windows attributes in st_win_attrs.

 (6) Set certain STATX_INFO_xxx to reflect a number of Windows file
     attributes:

	ATTR_TEMPORARY	-> STATX_INFO_TEMPORARY;
	ATTR_ENCRYPTED	-> STATX_INFO_ENCRYPTED;

 (7) Set STATX_INFO_REMOTE on all files fetched by CIFS.

 (8) Set STATX_INFO_NONSYSTEM_OWNERSHIP on all files as they all have
     Windows ownership details too.

Furthermore, what cifs_getattr() does can be controlled as follows:

 (1) If AT_NO_ATTR_SYNC is indicated then this will suppress the flushing
     of outstanding writes and the rereading of the inode's attributes with
     the server as detailed below.

 (2) Otherwise:

     (a) If AT_FORCE_ATTR_SYNC is indicated, or mtime, ctime or size are
     	 requested then the outstanding writes will be written to the
     	 server first.

     (b) The inode's attributes will be reread from the server:

     	 (i) if AT_FORCE_ATTR_SYNC is indicated;

        (ii) if the cached attributes have expired;

       (iii) extra attributes are requested that aren't normally stored.

If the inode isn't synchronised, then the cached attributes will be used -
even if expired - without reference to the server.  Some attributes may be
unavailable that would otherwise be provided.

Note that cifs_revalidate_dentry() will issue an extra operation to get the
FILE_ALL_INFO in addition to the FILE_UNIX_BASIC_INFO if it needs to
collect creation time and attributes on behalf of cifs_getattr().

[NOTE: THIS PATCH IS UNTESTED!]

Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/cifs/cifsfs.h   |    4 +-
 fs/cifs/cifsglob.h |    8 ++++
 fs/cifs/dir.c      |    2 -
 fs/cifs/inode.c    |  117 ++++++++++++++++++++++++++++++++++++++++------------
 4 files changed, 101 insertions(+), 30 deletions(-)

diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h
index 83aac8ba50b0..304f4567d207 100644
--- a/fs/cifs/cifsfs.h
+++ b/fs/cifs/cifsfs.h
@@ -67,9 +67,9 @@ extern int cifs_rmdir(struct inode *, struct dentry *);
 extern int cifs_rename2(struct inode *, struct dentry *, struct inode *,
 			struct dentry *, unsigned int);
 extern int cifs_revalidate_file_attr(struct file *filp);
-extern int cifs_revalidate_dentry_attr(struct dentry *);
+extern int cifs_revalidate_dentry_attr(struct dentry *, bool, bool);
 extern int cifs_revalidate_file(struct file *filp);
-extern int cifs_revalidate_dentry(struct dentry *);
+extern int cifs_revalidate_dentry(struct dentry *, bool, bool);
 extern int cifs_invalidate_mapping(struct inode *inode);
 extern int cifs_revalidate_mapping(struct inode *inode);
 extern int cifs_zap_mapping(struct inode *inode);
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index f2cc0b3d1af7..3225b16f7522 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -1166,7 +1166,11 @@ struct cifsInodeInfo {
 	unsigned long flags;
 	spinlock_t writers_lock;
 	unsigned int writers;		/* Number of writers on this inode */
+	bool btime_valid:1;		/* stored creation time is valid */
+	bool uid_faked:1;		/* true if i_uid is faked */
+	bool gid_faked:1;		/* true if i_gid is faked */
 	unsigned long time;		/* jiffies of last update of inode */
+	struct timespec btime;		/* creation time */
 	u64  server_eof;		/* current file size on server -- protected by i_lock */
 	u64  uniqueid;			/* server inode number */
 	u64  createtime;		/* creation time on server */
@@ -1379,6 +1383,9 @@ struct dfs_info3_param {
 #define CIFS_FATTR_NEED_REVAL		0x4
 #define CIFS_FATTR_INO_COLLISION	0x8
 #define CIFS_FATTR_UNKNOWN_NLINK	0x10
+#define CIFS_FATTR_WINATTRS_VALID	0x20	/* T if cf_btime and cf_cifsattrs valid */
+#define CIFS_FATTR_UID_FAKED		0x40	/* T if cf_uid is faked */
+#define CIFS_FATTR_GID_FAKED		0x80	/* T if cf_gid is faked */
 
 struct cifs_fattr {
 	u32		cf_flags;
@@ -1396,6 +1403,7 @@ struct cifs_fattr {
 	struct timespec	cf_atime;
 	struct timespec	cf_mtime;
 	struct timespec	cf_ctime;
+	struct timespec	cf_btime;
 };
 
 static inline void free_dfs_info_param(struct dfs_info3_param *param)
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index c3eb998a99bd..4984f04b0677 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -792,7 +792,7 @@ cifs_d_revalidate(struct dentry *direntry, unsigned int flags)
 		return -ECHILD;
 
 	if (d_really_is_positive(direntry)) {
-		if (cifs_revalidate_dentry(direntry))
+		if (cifs_revalidate_dentry(direntry, false, false))
 			return 0;
 		else {
 			/*
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index 5f9ad5c42180..dc1814b70c81 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -166,13 +166,21 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr)
 	cifs_nlink_fattr_to_inode(inode, fattr);
 	inode->i_uid = fattr->cf_uid;
 	inode->i_gid = fattr->cf_gid;
+	if (fattr->cf_flags & CIFS_FATTR_UID_FAKED)
+		cifs_i->uid_faked = true;
+	if (fattr->cf_flags & CIFS_FATTR_GID_FAKED)
+		cifs_i->gid_faked = true;
 
 	/* if dynperm is set, don't clobber existing mode */
 	if (inode->i_state & I_NEW ||
 	    !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM))
 		inode->i_mode = fattr->cf_mode;
 
-	cifs_i->cifsAttrs = fattr->cf_cifsattrs;
+	if (fattr->cf_flags & CIFS_FATTR_WINATTRS_VALID) {
+		cifs_i->cifsAttrs = fattr->cf_cifsattrs;
+		cifs_i->btime = fattr->cf_btime;
+		cifs_i->btime_valid = true;
+	}
 
 	if (fattr->cf_flags & CIFS_FATTR_NEED_REVAL)
 		cifs_i->time = 0;
@@ -284,18 +292,22 @@ cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, FILE_UNIX_BASIC_INFO *info,
 		u64 id = le64_to_cpu(info->Uid);
 		if (id < ((uid_t)-1)) {
 			kuid_t uid = make_kuid(&init_user_ns, id);
-			if (uid_valid(uid))
+			if (uid_valid(uid)) {
 				fattr->cf_uid = uid;
+				fattr->cf_flags |= CIFS_FATTR_UID_FAKED;
+			}
 		}
 	}
-	
+
 	fattr->cf_gid = cifs_sb->mnt_gid;
 	if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)) {
 		u64 id = le64_to_cpu(info->Gid);
 		if (id < ((gid_t)-1)) {
 			kgid_t gid = make_kgid(&init_user_ns, id);
-			if (gid_valid(gid))
+			if (gid_valid(gid)) {
 				fattr->cf_gid = gid;
+				fattr->cf_flags |= CIFS_FATTR_GID_FAKED;
+			}
 		}
 	}
 
@@ -324,7 +336,8 @@ cifs_create_dfs_fattr(struct cifs_fattr *fattr, struct super_block *sb)
 	fattr->cf_ctime = CURRENT_TIME;
 	fattr->cf_mtime = CURRENT_TIME;
 	fattr->cf_nlink = 2;
-	fattr->cf_flags |= CIFS_FATTR_DFS_REFERRAL;
+	fattr->cf_flags |= CIFS_FATTR_DFS_REFERRAL |
+		CIFS_FATTR_UID_FAKED | CIFS_FATTR_GID_FAKED;
 }
 
 static int
@@ -590,6 +603,7 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
 	struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
 
 	memset(fattr, 0, sizeof(*fattr));
+	fattr->cf_flags = CIFS_FATTR_WINATTRS_VALID;
 	fattr->cf_cifsattrs = le32_to_cpu(info->Attributes);
 	if (info->DeletePending)
 		fattr->cf_flags |= CIFS_FATTR_DELETE_PENDING;
@@ -601,6 +615,7 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
 
 	fattr->cf_ctime = cifs_NTtimeToUnix(info->ChangeTime);
 	fattr->cf_mtime = cifs_NTtimeToUnix(info->LastWriteTime);
+	fattr->cf_btime = cifs_NTtimeToUnix(info->CreationTime);
 
 	if (adjust_tz) {
 		fattr->cf_ctime.tv_sec += tcon->ses->server->timeAdj;
@@ -1907,7 +1922,8 @@ int cifs_revalidate_file_attr(struct file *filp)
 	return rc;
 }
 
-int cifs_revalidate_dentry_attr(struct dentry *dentry)
+int cifs_revalidate_dentry_attr(struct dentry *dentry,
+				bool want_extra_bits, bool force)
 {
 	unsigned int xid;
 	int rc = 0;
@@ -1918,7 +1934,7 @@ int cifs_revalidate_dentry_attr(struct dentry *dentry)
 	if (inode == NULL)
 		return -ENOENT;
 
-	if (!cifs_inode_needs_reval(inode))
+	if (!force && !cifs_inode_needs_reval(inode))
 		return rc;
 
 	xid = get_xid();
@@ -1935,9 +1951,12 @@ int cifs_revalidate_dentry_attr(struct dentry *dentry)
 		 full_path, inode, inode->i_count.counter,
 		 dentry, dentry->d_time, jiffies);
 
-	if (cifs_sb_master_tcon(CIFS_SB(sb))->unix_ext)
+	if (cifs_sb_master_tcon(CIFS_SB(sb))->unix_ext) {
 		rc = cifs_get_inode_info_unix(&inode, full_path, sb, xid);
-	else
+		if (rc != 0)
+			goto out;
+	}
+	if (!cifs_sb_master_tcon(CIFS_SB(sb))->unix_ext || want_extra_bits)
 		rc = cifs_get_inode_info(&inode, full_path, NULL, sb,
 					 xid, NULL);
 
@@ -1960,12 +1979,13 @@ int cifs_revalidate_file(struct file *filp)
 }
 
 /* revalidate a dentry's inode attributes */
-int cifs_revalidate_dentry(struct dentry *dentry)
+int cifs_revalidate_dentry(struct dentry *dentry,
+			   bool want_extra_bits, bool force)
 {
 	int rc;
 	struct inode *inode = d_inode(dentry);
 
-	rc = cifs_revalidate_dentry_attr(dentry);
+	rc = cifs_revalidate_dentry_attr(dentry, want_extra_bits, force);
 	if (rc)
 		return rc;
 
@@ -1978,28 +1998,62 @@ int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
 	struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
 	struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
 	struct inode *inode = d_inode(dentry);
+	struct cifsInodeInfo *cifs_i = CIFS_I(inode);
+	bool force = stat->query_flags & AT_FORCE_ATTR_SYNC;
+	bool want_extra_bits = false;
+	u32 info;
+	u32 attrs;
 	int rc;
 
-	/*
-	 * We need to be sure that all dirty pages are written and the server
-	 * has actual ctime, mtime and file length.
-	 */
-	if (!CIFS_CACHE_READ(CIFS_I(inode)) && inode->i_mapping &&
-	    inode->i_mapping->nrpages != 0) {
-		rc = filemap_fdatawait(inode->i_mapping);
-		if (rc) {
-			mapping_set_error(inode->i_mapping, rc);
-			return rc;
+	if (cifs_i->uid_faked)
+		stat->request_mask &= ~STATX_UID;
+	if (cifs_i->gid_faked)
+		stat->request_mask &= ~STATX_GID;
+
+	if ((stat->request_mask & STATX_BTIME && !cifs_i->btime_valid) ||
+	    stat->request_mask & STATX_WIN_ATTRS)
+		want_extra_bits = force = true;
+
+	if (!(stat->query_flags & AT_NO_ATTR_SYNC)) {
+		/* Unless we're explicitly told not to sync, we need to be sure
+		 * that all dirty pages are written and the server has actual
+		 * ctime, mtime and file length.
+		 */
+		bool flush = force;
+
+		if (stat->request_mask &
+		    (STATX_CTIME | STATX_MTIME | STATX_SIZE))
+			flush = true;
+
+		if (flush &&
+		    !CIFS_CACHE_READ(CIFS_I(inode)) && inode->i_mapping &&
+		    inode->i_mapping->nrpages != 0) {
+			rc = filemap_fdatawait(inode->i_mapping);
+			if (rc) {
+				mapping_set_error(inode->i_mapping, rc);
+				return rc;
+			}
 		}
-	}
 
-	rc = cifs_revalidate_dentry_attr(dentry);
-	if (rc)
-		return rc;
+		rc = cifs_revalidate_dentry(dentry, want_extra_bits, force);
+		if (rc)
+			return rc;
+	}
 
 	generic_fillattr(inode, stat);
 	stat->blksize = CIFS_MAX_MSGSIZE;
-	stat->ino = CIFS_I(inode)->uniqueid;
+
+	info = STATX_INFO_REMOTE | STATX_INFO_NONSYSTEM_OWNERSHIP;
+
+	if (cifs_i->btime_valid) {
+		stat->btime = cifs_i->btime;
+		stat->result_mask |= STATX_BTIME;
+	}
+
+	/* We don't promise an inode number if we made one up */
+	stat->ino = cifs_i->uniqueid;
+	if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM))
+		stat->result_mask &= ~STATX_INO;
 
 	/*
 	 * If on a multiuser mount without unix extensions or cifsacl being
@@ -2013,8 +2067,17 @@ int cifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
 			stat->uid = current_fsuid();
 		if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID))
 			stat->gid = current_fsgid();
+		stat->result_mask &= ~(STATX_UID | STATX_GID);
 	}
-	return rc;
+
+	attrs = cifs_i->cifsAttrs;
+	stat->win_attrs = attrs;
+	if (attrs & ATTR_TEMPORARY)	info |= STATX_INFO_TEMPORARY;
+	if (attrs & ATTR_ENCRYPTED)	info |= STATX_INFO_ENCRYPTED;
+	stat->information |= info;
+	stat->result_mask |= STATX_WIN_ATTRS;
+
+	return 0;
 }
 
 static int cifs_truncate_page(struct address_space *mapping, loff_t from)

[toc] | [prev] | [next] | [standalone]


#1391095 — [PATCH 3/6] statx: Ext4: Return enhanced file attributes

FromDavid Howells <dhowells@redhat.com>
Date2016-04-29 15:00 +0200
Subject[PATCH 3/6] statx: Ext4: Return enhanced file attributes
Message-ID<rtgbx-69i-41@gated-at.bofh.it>
In reply to#1391088
Return enhanced file attributes from the Ext4 filesystem.  This includes
the following:

 (1) The inode creation time (i_crtime) as i_btime, setting STATX_BTIME.

 (2) The inode i_version as st_version if a file with I_VERSION set or a
     directory, setting STATX_VERSION.

 (3) FS_xxx_FL flags are returned as for ioctl(FS_IOC_GETFLAGS), setting
     STATX_IOC_FLAGS.

This requires that all ext4 inodes have a getattr call, not just some of
them, so to this end, split the ext4_getattr() function and only call part
of it where appropriate.

Example output:

	[root@andromeda ~]# ./samples/statx/test-statx /usr
	statx(/usr) = 0
	results=37ef
	  Size: 4096            Blocks: 16         IO Block: 4096    directory
	Device: 08:02           Inode: 1572865     Links: 14
	Access: (0755/drwxr-xr-x)  Uid:     0   Gid:     0
	Access: 2015-11-03 16:12:30.000000000+0000
	Modify: 2013-10-18 15:29:18.000000000+0100
	Change: 2013-10-18 15:29:18.000000000+0100
	Data version: 2fh
	Inode flags: 00000000 (-------- -------- -------- --------)
	IO-blocksize: blksize=4096

Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/ext4/ext4.h    |    2 ++
 fs/ext4/file.c    |    2 +-
 fs/ext4/inode.c   |   30 +++++++++++++++++++++++++++---
 fs/ext4/namei.c   |    2 ++
 fs/ext4/symlink.c |    2 ++
 5 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 349afebe21ee..2f25eaa63f39 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2549,6 +2549,8 @@ extern int  ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
 				struct kstat *stat);
 extern void ext4_evict_inode(struct inode *);
 extern void ext4_clear_inode(struct inode *);
+extern int  ext4_file_getattr(struct vfsmount *mnt, struct dentry *dentry,
+			      struct kstat *stat);
 extern int  ext4_sync_inode(handle_t *, struct inode *);
 extern void ext4_dirty_inode(struct inode *, int);
 extern int ext4_change_inode_journal_flag(struct inode *, int);
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index fa2208bae2e1..45c7b8644d0e 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -715,7 +715,7 @@ const struct file_operations ext4_file_operations = {
 
 const struct inode_operations ext4_file_inode_operations = {
 	.setattr	= ext4_setattr,
-	.getattr	= ext4_getattr,
+	.getattr	= ext4_file_getattr,
 	.setxattr	= generic_setxattr,
 	.getxattr	= generic_getxattr,
 	.listxattr	= ext4_listxattr,
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 981a1fc30eaa..309b6cff8afc 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5100,11 +5100,35 @@ err_out:
 int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
 		 struct kstat *stat)
 {
-	struct inode *inode;
-	unsigned long long delalloc_blocks;
+	struct inode *inode = d_inode(dentry);
+	struct ext4_inode *raw_inode;
+	struct ext4_inode_info *ei = EXT4_I(inode);
+
+	stat->result_mask |= STATX_GEN;
+	stat->gen = inode->i_generation;
+
+	if (EXT4_FITS_IN_INODE(raw_inode, ei, i_crtime)) {
+		stat->result_mask |= STATX_BTIME;
+		stat->btime.tv_sec = ei->i_crtime.tv_sec;
+		stat->btime.tv_nsec = ei->i_crtime.tv_nsec;
+	}
+
+	if (S_ISDIR(inode->i_mode) || IS_I_VERSION(inode)) {
+		stat->result_mask |= STATX_VERSION;
+		stat->version = inode->i_version;
+	}
 
-	inode = d_inode(dentry);
 	generic_fillattr(inode, stat);
+	return 0;
+}
+
+int ext4_file_getattr(struct vfsmount *mnt, struct dentry *dentry,
+		      struct kstat *stat)
+{
+	struct inode *inode = dentry->d_inode;
+	u64 delalloc_blocks;
+
+	ext4_getattr(mnt, dentry, stat);
 
 	/*
 	 * If there is inline data in the inode, the inode will normally not
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 48e4b8907826..9b5fdc971e22 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -3882,6 +3882,7 @@ const struct inode_operations ext4_dir_inode_operations = {
 	.tmpfile	= ext4_tmpfile,
 	.rename2	= ext4_rename2,
 	.setattr	= ext4_setattr,
+	.getattr	= ext4_getattr,
 	.setxattr	= generic_setxattr,
 	.getxattr	= generic_getxattr,
 	.listxattr	= ext4_listxattr,
@@ -3893,6 +3894,7 @@ const struct inode_operations ext4_dir_inode_operations = {
 
 const struct inode_operations ext4_special_inode_operations = {
 	.setattr	= ext4_setattr,
+	.getattr	= ext4_getattr,
 	.setxattr	= generic_setxattr,
 	.getxattr	= generic_getxattr,
 	.listxattr	= ext4_listxattr,
diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c
index 75ed5c2f0c16..54015f3d7516 100644
--- a/fs/ext4/symlink.c
+++ b/fs/ext4/symlink.c
@@ -105,6 +105,7 @@ const struct inode_operations ext4_symlink_inode_operations = {
 	.readlink	= generic_readlink,
 	.get_link	= page_get_link,
 	.setattr	= ext4_setattr,
+	.getattr	= ext4_getattr,
 	.setxattr	= generic_setxattr,
 	.getxattr	= generic_getxattr,
 	.listxattr	= ext4_listxattr,
@@ -115,6 +116,7 @@ const struct inode_operations ext4_fast_symlink_inode_operations = {
 	.readlink	= generic_readlink,
 	.get_link	= simple_get_link,
 	.setattr	= ext4_setattr,
+	.getattr	= ext4_getattr,
 	.setxattr	= generic_setxattr,
 	.getxattr	= generic_getxattr,
 	.listxattr	= ext4_listxattr,

[toc] | [prev] | [next] | [standalone]


#1392552 — Re: [PATCH 3/6] statx: Ext4: Return enhanced file attributes

FromAndreas Dilger <adilger@dilger.ca>
Date2016-05-03 00:50 +0200
SubjectRe: [PATCH 3/6] statx: Ext4: Return enhanced file attributes
Message-ID<ruuP8-419-5@gated-at.bofh.it>
In reply to#1391095

[Multipart message — attachments visible in raw view] — view raw

On Apr 29, 2016, at 6:57 AM, David Howells <dhowells@redhat.com> wrote:
> 
> Return enhanced file attributes from the Ext4 filesystem.  This includes
> the following:
> 
> (1) The inode creation time (i_crtime) as i_btime, setting STATX_BTIME.
> 
> (2) The inode i_version as st_version if a file with I_VERSION set or a
>     directory, setting STATX_VERSION.
> 
> (3) FS_xxx_FL flags are returned as for ioctl(FS_IOC_GETFLAGS), setting
>     STATX_IOC_FLAGS.

I don't see where this is implemented in this patch, and it should be
removed from the commit message to avoid confusion.

> This requires that all ext4 inodes have a getattr call, not just some of
> them, so to this end, split the ext4_getattr() function and only call part
> of it where appropriate.
> 
> Example output:
> 
> 	[root@andromeda ~]# ./samples/statx/test-statx /usr
> 	statx(/usr) = 0
> 	results=37ef
> 	  Size: 4096            Blocks: 16         IO Block: 4096    directory
> 	Device: 08:02           Inode: 1572865     Links: 14
> 	Access: (0755/drwxr-xr-x)  Uid:     0   Gid:     0
> 	Access: 2015-11-03 16:12:30.000000000+0000
> 	Modify: 2013-10-18 15:29:18.000000000+0100
> 	Change: 2013-10-18 15:29:18.000000000+0100
> 	Data version: 2fh
> 	Inode flags: 00000000 (-------- -------- -------- --------)
> 	IO-blocksize: blksize=4096

One minor strangeness in this commit message is that the above usage example
doesn't include nanoseconds or Birth time for ext4, when this should be
supported for all ext4 filesystems?  Was this example run on an older ext3
filesystem (or some filesystem upgraded from ext3)?  Any ext4-formatted fs
should have the larger inode size to handle these extra fields.

Also a bit strange that "IO Block: 4096" and "IO-blocksize: blksize=4096"
is listed twice, but that seems to be an issue with the test-statx tool
and not necessarily the data being returned.

Cheers, Andreas

> 
> Signed-off-by: David Howells <dhowells@redhat.com>
> ---
> 
> fs/ext4/ext4.h    |    2 ++
> fs/ext4/file.c    |    2 +-
> fs/ext4/inode.c   |   30 +++++++++++++++++++++++++++---
> fs/ext4/namei.c   |    2 ++
> fs/ext4/symlink.c |    2 ++
> 5 files changed, 34 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index 349afebe21ee..2f25eaa63f39 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -2549,6 +2549,8 @@ extern int  ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
> 				struct kstat *stat);
> extern void ext4_evict_inode(struct inode *);
> extern void ext4_clear_inode(struct inode *);
> +extern int  ext4_file_getattr(struct vfsmount *mnt, struct dentry *dentry,
> +			      struct kstat *stat);
> extern int  ext4_sync_inode(handle_t *, struct inode *);
> extern void ext4_dirty_inode(struct inode *, int);
> extern int ext4_change_inode_journal_flag(struct inode *, int);
> diff --git a/fs/ext4/file.c b/fs/ext4/file.c
> index fa2208bae2e1..45c7b8644d0e 100644
> --- a/fs/ext4/file.c
> +++ b/fs/ext4/file.c
> @@ -715,7 +715,7 @@ const struct file_operations ext4_file_operations = {
> 
> const struct inode_operations ext4_file_inode_operations = {
> 	.setattr	= ext4_setattr,
> -	.getattr	= ext4_getattr,
> +	.getattr	= ext4_file_getattr,
> 	.setxattr	= generic_setxattr,
> 	.getxattr	= generic_getxattr,
> 	.listxattr	= ext4_listxattr,
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 981a1fc30eaa..309b6cff8afc 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -5100,11 +5100,35 @@ err_out:
> int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
> 		 struct kstat *stat)
> {
> -	struct inode *inode;
> -	unsigned long long delalloc_blocks;
> +	struct inode *inode = d_inode(dentry);
> +	struct ext4_inode *raw_inode;
> +	struct ext4_inode_info *ei = EXT4_I(inode);
> +
> +	stat->result_mask |= STATX_GEN;
> +	stat->gen = inode->i_generation;
> +
> +	if (EXT4_FITS_IN_INODE(raw_inode, ei, i_crtime)) {
> +		stat->result_mask |= STATX_BTIME;
> +		stat->btime.tv_sec = ei->i_crtime.tv_sec;
> +		stat->btime.tv_nsec = ei->i_crtime.tv_nsec;
> +	}
> +
> +	if (S_ISDIR(inode->i_mode) || IS_I_VERSION(inode)) {
> +		stat->result_mask |= STATX_VERSION;
> +		stat->version = inode->i_version;
> +	}
> 
> -	inode = d_inode(dentry);
> 	generic_fillattr(inode, stat);
> +	return 0;
> +}
> +
> +int ext4_file_getattr(struct vfsmount *mnt, struct dentry *dentry,
> +		      struct kstat *stat)
> +{
> +	struct inode *inode = dentry->d_inode;
> +	u64 delalloc_blocks;
> +
> +	ext4_getattr(mnt, dentry, stat);
> 
> 	/*
> 	 * If there is inline data in the inode, the inode will normally not
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 48e4b8907826..9b5fdc971e22 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -3882,6 +3882,7 @@ const struct inode_operations ext4_dir_inode_operations = {
> 	.tmpfile	= ext4_tmpfile,
> 	.rename2	= ext4_rename2,
> 	.setattr	= ext4_setattr,
> +	.getattr	= ext4_getattr,
> 	.setxattr	= generic_setxattr,
> 	.getxattr	= generic_getxattr,
> 	.listxattr	= ext4_listxattr,
> @@ -3893,6 +3894,7 @@ const struct inode_operations ext4_dir_inode_operations = {
> 
> const struct inode_operations ext4_special_inode_operations = {
> 	.setattr	= ext4_setattr,
> +	.getattr	= ext4_getattr,
> 	.setxattr	= generic_setxattr,
> 	.getxattr	= generic_getxattr,
> 	.listxattr	= ext4_listxattr,
> diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c
> index 75ed5c2f0c16..54015f3d7516 100644
> --- a/fs/ext4/symlink.c
> +++ b/fs/ext4/symlink.c
> @@ -105,6 +105,7 @@ const struct inode_operations ext4_symlink_inode_operations = {
> 	.readlink	= generic_readlink,
> 	.get_link	= page_get_link,
> 	.setattr	= ext4_setattr,
> +	.getattr	= ext4_getattr,
> 	.setxattr	= generic_setxattr,
> 	.getxattr	= generic_getxattr,
> 	.listxattr	= ext4_listxattr,
> @@ -115,6 +116,7 @@ const struct inode_operations ext4_fast_symlink_inode_operations = {
> 	.readlink	= generic_readlink,
> 	.get_link	= simple_get_link,
> 	.setattr	= ext4_setattr,
> +	.getattr	= ext4_getattr,
> 	.setxattr	= generic_setxattr,
> 	.getxattr	= generic_getxattr,
> 	.listxattr	= ext4_listxattr,
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


Cheers, Andreas





[toc] | [prev] | [next] | [standalone]


#1393792 — Re: [PATCH 3/6] statx: Ext4: Return enhanced file attributes

FromDavid Howells <dhowells@redhat.com>
Date2016-05-03 22:30 +0200
SubjectRe: [PATCH 3/6] statx: Ext4: Return enhanced file attributes
Message-ID<ruP7e-6xa-53@gated-at.bofh.it>
In reply to#1392552
Andreas Dilger <adilger@dilger.ca> wrote:

> > (3) FS_xxx_FL flags are returned as for ioctl(FS_IOC_GETFLAGS), setting
> >     STATX_IOC_FLAGS.
> 
> I don't see where this is implemented in this patch, and it should be
> removed from the commit message to avoid confusion.

Oops - I forgot to remove it from the other patches.

David

[toc] | [prev] | [next] | [standalone]


#1396391 — Re: [PATCH 3/6] statx: Ext4: Return enhanced file attributes

FromChristoph Hellwig <hch@infradead.org>
Date2016-05-08 10:40 +0200
SubjectRe: [PATCH 3/6] statx: Ext4: Return enhanced file attributes
Message-ID<rwspP-3md-3@gated-at.bofh.it>
In reply to#1391095
On Fri, Apr 29, 2016 at 01:57:59PM +0100, David Howells wrote:
>  (3) FS_xxx_FL flags are returned as for ioctl(FS_IOC_GETFLAGS), setting
>      STATX_IOC_FLAGS.

Doesn't look like it is.  Which actually is a good thing given how much
of a mess FS_IOC_GETFLAGS is.

[toc] | [prev] | [next] | [standalone]


#1391114 — [PATCH 5/6] statx: Make windows attributes available for CIFS, NTFS and FAT to use

FromDavid Howells <dhowells@redhat.com>
Date2016-04-29 15:10 +0200
Subject[PATCH 5/6] statx: Make windows attributes available for CIFS, NTFS and FAT to use
Message-ID<rtgle-6wl-47@gated-at.bofh.it>
In reply to#1391088
Make windows attributes available for CIFS, NTFS and FAT to use in the
statx struct.  The attribute flags map directly by value to those in the
CIFS PDU flags.  Some of these bits can also be used by JFS, UFS and HPFS.

The statx struct acquires:

	__u32	st_win_attrs;

The value in this is present if STATX_WIN_ATTRS is set.

The defined flags in this are:

	STATX_WIN_ATTR_READONLY
	STATX_WIN_ATTR_HIDDEN
	STATX_WIN_ATTR_SYSTEM
	STATX_WIN_ATTR_DIRECTORY
	STATX_WIN_ATTR_ARCHIVE
	STATX_WIN_ATTR_NORMAL
	STATX_WIN_ATTR_TEMPORARY
	STATX_WIN_ATTR_SPARSE_FILE
	STATX_WIN_ATTR_REPARSE_POINT
	STATX_WIN_ATTR_COMPRESSED
	STATX_WIN_ATTR_OFFLINE
	STATX_WIN_ATTR_NOT_CONTENT_INDEXED
	STATX_WIN_ATTR_ENCRYPTED
	STATX_WIN_ATTR_INTEGRITY_STREAM
	STATX_WIN_ATTR_NO_SCRUB_DATA

Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/stat.c                  |    5 ++++-
 include/uapi/linux/stat.h  |   30 ++++++++++++++++++++++++++++--
 samples/statx/test-statx.c |   31 +++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/fs/stat.c b/fs/stat.c
index c2f8370dab13..1552bff154e6 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -83,6 +83,7 @@ int vfs_xgetattr_nosec(struct path *path, struct kstat *stat)
 
 	stat->result_mask = 0;
 	stat->information = 0;
+	stat->win_attrs = 0;
 	if (inode->i_op->getattr)
 		return inode->i_op->getattr(path->mnt, path->dentry, stat);
 
@@ -643,7 +644,9 @@ static long statx_set_result(struct kstat *stat, struct statx __user *buffer)
 	    __put_user(stat->blocks,		&buffer->st_blocks	) ||
 	    __put_user(stat->version,		&buffer->st_version	) ||
 	    __put_user(stat->gen,		&buffer->st_gen		) ||
-	    __clear_user(&buffer->__spare1, sizeof(buffer->__spare1)))
+	    __put_user(stat->win_attrs,		&buffer->st_win_attrs	) ||
+	    __clear_user(&buffer->__spare1,
+			 sizeof(buffer->__spare1) + sizeof(buffer->__spare2)))
 		return -EFAULT;
 
 	return 0;
diff --git a/include/uapi/linux/stat.h b/include/uapi/linux/stat.h
index 55ce6607dab6..64729b0785bf 100644
--- a/include/uapi/linux/stat.h
+++ b/include/uapi/linux/stat.h
@@ -106,7 +106,10 @@ struct statx {
 	__u32	st_dev_major;	/* ID of device containing file [uncond] */
 	__u32	st_dev_minor;
 	/* 0x80 */
-	__u64	__spare1[16];	/* Spare space for future expansion */
+	__u32	st_win_attrs;	/* Windows file attributes */
+	__u32	__spare1[3];
+	/* 0x90 */
+	__u64	__spare2[14];	/* Spare space for future expansion */
 	/* 0x100 */
 };
 
@@ -133,7 +136,8 @@ struct statx {
 #define STATX_BTIME		0x00000800U	/* Want/got st_btime */
 #define STATX_VERSION		0x00001000U	/* Want/got st_version */
 #define STATX_GEN		0x00002000U	/* Want/got st_gen */
-#define STATX_ALL_STATS		0x00003fffU	/* All supported stats */
+#define STATX_WIN_ATTRS		0x00004000U	/* Want/got st_win_attrs */
+#define STATX_ALL_STATS		0x00007fffU	/* All supported stats */
 
 /*
  * Flags to be found in st_information
@@ -151,4 +155,26 @@ struct statx {
 #define STATX_INFO_AUTODIR		0x00000040U /* Dir provides unlisted automounts */
 #define STATX_INFO_NONSYSTEM_OWNERSHIP	0x00000080U /* File has non-system ownership details */
 
+/*
+ * Flags to be found in st_win_attrs.
+ *
+ * These give information about the state of a file on a Windows filesystem
+ * (such as. FAT, NTFS, CIFS).  These values are borrowed from the CIFS fs.
+ */
+#define STATX_WIN_ATTR_READONLY			0x00000001
+#define STATX_WIN_ATTR_HIDDEN			0x00000002
+#define STATX_WIN_ATTR_SYSTEM			0x00000004
+#define STATX_WIN_ATTR_DIRECTORY		0x00000010
+#define STATX_WIN_ATTR_ARCHIVE			0x00000020
+#define STATX_WIN_ATTR_NORMAL			0x00000080
+#define STATX_WIN_ATTR_TEMPORARY		0x00000100
+#define STATX_WIN_ATTR_SPARSE_FILE		0x00000200
+#define STATX_WIN_ATTR_REPARSE_POINT		0x00000400
+#define STATX_WIN_ATTR_COMPRESSED		0x00000800
+#define STATX_WIN_ATTR_OFFLINE			0x00001000
+#define STATX_WIN_ATTR_NOT_CONTENT_INDEXED	0x00002000
+#define STATX_WIN_ATTR_ENCRYPTED		0x00004000
+#define STATX_WIN_ATTR_INTEGRITY_STREAM		0x00008000
+#define STATX_WIN_ATTR_NO_SCRUB_DATA		0x00020000
+
 #endif /* _UAPI_LINUX_STAT_H */
diff --git a/samples/statx/test-statx.c b/samples/statx/test-statx.c
index 38ef23c12e7d..86eac7d16c32 100644
--- a/samples/statx/test-statx.c
+++ b/samples/statx/test-statx.c
@@ -134,6 +134,37 @@ static void dump_statx(struct statx *stx)
 	if (stx->st_mask & STATX_GEN)
 		printf("Inode gen   : %xh\n", stx->st_gen);
 
+	if (stx->st_mask & STATX_WIN_ATTRS) {
+		unsigned char bits;
+		int loop, byte;
+
+		static char wattr_representation[32 + 1] =
+			/* STATX_WIN_ATTR_ flags: */
+			"????????"	/* 31-24	0x00000000-ff000000 */
+			"??????N?"	/* 23-16	0x00000000-00ff0000 */
+			"ieNocrst"	/* 15- 8	0x00000000-0000ff00 */
+			"n?Ad?SHR"	/*  7- 0	0x00000000-000000ff */
+			;
+
+		printf("Win attrs  : %08llx (",
+		       (unsigned long long)stx->st_win_attrs);
+		for (byte = 32 - 8; byte >= 0; byte -= 8) {
+			bits = stx->st_win_attrs >> byte;
+			for (loop = 7; loop >= 0; loop--) {
+				int bit = byte + loop;
+
+				if (bits & 0x80)
+					putchar(wattr_representation[31 - bit]);
+				else
+					putchar('-');
+				bits <<= 1;
+			}
+			if (byte)
+				putchar(' ');
+		}
+		printf(")\n");
+	}
+
 	if (stx->st_information) {
 		unsigned char bits;
 		int loop, byte;

[toc] | [prev] | [next] | [standalone]


#1392556 — Re: [PATCH 5/6] statx: Make windows attributes available for CIFS, NTFS and FAT to use

FromAndreas Dilger <adilger@dilger.ca>
Date2016-05-03 01:00 +0200
SubjectRe: [PATCH 5/6] statx: Make windows attributes available for CIFS, NTFS and FAT to use
Message-ID<ruuYO-46k-15@gated-at.bofh.it>
In reply to#1391114

[Multipart message — attachments visible in raw view] — view raw

On Apr 29, 2016, at 6:58 AM, David Howells <dhowells@redhat.com> wrote:
> 
> Make windows attributes available for CIFS, NTFS and FAT to use in the
> statx struct.  The attribute flags map directly by value to those in the
> CIFS PDU flags.  Some of these bits can also be used by JFS, UFS and HPFS.
> 
> The statx struct acquires:
> 
> 	__u32	st_win_attrs;

It seems some of these flags are duplicated with the st_information field,
and some are duplicate with FS_IOC_GETFLAGS values, and returning the same
information in multiple ways is confusing.

If these flags are part of the CIFS protocol, and are directly usable by
Samba then I can understand we wouldn't want to change them once in the
kernel and then convert them back in userspace, but I'm a bit reluctant
to have flags only for CIFS/NTFS/FAT that might also be useful for other filesystems.  Would we want to be able to get translated st_win_attrs
flags in ext4 attrs when it is being exported by Samba?

> The value in this is present if STATX_WIN_ATTRS is set.
> 
> The defined flags in this are:
> 
> 	STATX_WIN_ATTR_READONLY
> 	STATX_WIN_ATTR_HIDDEN
> 	STATX_WIN_ATTR_SYSTEM
> 	STATX_WIN_ATTR_DIRECTORY

How does this differ from (st_mode & S_IFMT) == S_IFDIR)?

> 	STATX_WIN_ATTR_ARCHIVE
> 	STATX_WIN_ATTR_NORMAL

How does this differ from (st_mode & S_IFMT) == S_IFREG)?

> 	STATX_WIN_ATTR_TEMPORARY

How does this differ from STATX_INFO_TEMPORARY?

> 	STATX_WIN_ATTR_SPARSE_FILE
> 	STATX_WIN_ATTR_REPARSE_POINT
> 	STATX_WIN_ATTR_COMPRESSED
> 	STATX_WIN_ATTR_OFFLINE
> 	STATX_WIN_ATTR_NOT_CONTENT_INDEXED
> 	STATX_WIN_ATTR_ENCRYPTED

How does this differ from STATX_INFO_ENCRYPTED?

Cheers, Andreas

> 	STATX_WIN_ATTR_INTEGRITY_STREAM
> 	STATX_WIN_ATTR_NO_SCRUB_DATA
> 
> Signed-off-by: David Howells <dhowells@redhat.com>
> ---
> 
> fs/stat.c                  |    5 ++++-
> include/uapi/linux/stat.h  |   30 ++++++++++++++++++++++++++++--
> samples/statx/test-statx.c |   31 +++++++++++++++++++++++++++++++
> 3 files changed, 63 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/stat.c b/fs/stat.c
> index c2f8370dab13..1552bff154e6 100644
> --- a/fs/stat.c
> +++ b/fs/stat.c
> @@ -83,6 +83,7 @@ int vfs_xgetattr_nosec(struct path *path, struct kstat *stat)
> 
> 	stat->result_mask = 0;
> 	stat->information = 0;
> +	stat->win_attrs = 0;
> 	if (inode->i_op->getattr)
> 		return inode->i_op->getattr(path->mnt, path->dentry, stat);
> 
> @@ -643,7 +644,9 @@ static long statx_set_result(struct kstat *stat, struct statx __user *buffer)
> 	    __put_user(stat->blocks,		&buffer->st_blocks	) ||
> 	    __put_user(stat->version,		&buffer->st_version	) ||
> 	    __put_user(stat->gen,		&buffer->st_gen		) ||
> -	    __clear_user(&buffer->__spare1, sizeof(buffer->__spare1)))
> +	    __put_user(stat->win_attrs,		&buffer->st_win_attrs	) ||
> +	    __clear_user(&buffer->__spare1,
> +			 sizeof(buffer->__spare1) + sizeof(buffer->__spare2)))
> 		return -EFAULT;
> 
> 	return 0;
> diff --git a/include/uapi/linux/stat.h b/include/uapi/linux/stat.h
> index 55ce6607dab6..64729b0785bf 100644
> --- a/include/uapi/linux/stat.h
> +++ b/include/uapi/linux/stat.h
> @@ -106,7 +106,10 @@ struct statx {
> 	__u32	st_dev_major;	/* ID of device containing file [uncond] */
> 	__u32	st_dev_minor;
> 	/* 0x80 */
> -	__u64	__spare1[16];	/* Spare space for future expansion */
> +	__u32	st_win_attrs;	/* Windows file attributes */
> +	__u32	__spare1[3];
> +	/* 0x90 */
> +	__u64	__spare2[14];	/* Spare space for future expansion */
> 	/* 0x100 */
> };
> 
> @@ -133,7 +136,8 @@ struct statx {
> #define STATX_BTIME		0x00000800U	/* Want/got st_btime */
> #define STATX_VERSION		0x00001000U	/* Want/got st_version */
> #define STATX_GEN		0x00002000U	/* Want/got st_gen */
> -#define STATX_ALL_STATS		0x00003fffU	/* All supported stats */
> +#define STATX_WIN_ATTRS		0x00004000U	/* Want/got st_win_attrs */
> +#define STATX_ALL_STATS		0x00007fffU	/* All supported stats */
> 
> /*
>  * Flags to be found in st_information
> @@ -151,4 +155,26 @@ struct statx {
> #define STATX_INFO_AUTODIR		0x00000040U /* Dir provides unlisted automounts */
> #define STATX_INFO_NONSYSTEM_OWNERSHIP	0x00000080U /* File has non-system ownership details */
> 
> +/*
> + * Flags to be found in st_win_attrs.
> + *
> + * These give information about the state of a file on a Windows filesystem
> + * (such as. FAT, NTFS, CIFS).  These values are borrowed from the CIFS fs.
> + */
> +#define STATX_WIN_ATTR_READONLY			0x00000001
> +#define STATX_WIN_ATTR_HIDDEN			0x00000002
> +#define STATX_WIN_ATTR_SYSTEM			0x00000004
> +#define STATX_WIN_ATTR_DIRECTORY		0x00000010
> +#define STATX_WIN_ATTR_ARCHIVE			0x00000020
> +#define STATX_WIN_ATTR_NORMAL			0x00000080
> +#define STATX_WIN_ATTR_TEMPORARY		0x00000100
> +#define STATX_WIN_ATTR_SPARSE_FILE		0x00000200
> +#define STATX_WIN_ATTR_REPARSE_POINT		0x00000400
> +#define STATX_WIN_ATTR_COMPRESSED		0x00000800
> +#define STATX_WIN_ATTR_OFFLINE			0x00001000
> +#define STATX_WIN_ATTR_NOT_CONTENT_INDEXED	0x00002000
> +#define STATX_WIN_ATTR_ENCRYPTED		0x00004000
> +#define STATX_WIN_ATTR_INTEGRITY_STREAM		0x00008000
> +#define STATX_WIN_ATTR_NO_SCRUB_DATA		0x00020000
> +
> #endif /* _UAPI_LINUX_STAT_H */
> diff --git a/samples/statx/test-statx.c b/samples/statx/test-statx.c
> index 38ef23c12e7d..86eac7d16c32 100644
> --- a/samples/statx/test-statx.c
> +++ b/samples/statx/test-statx.c
> @@ -134,6 +134,37 @@ static void dump_statx(struct statx *stx)
> 	if (stx->st_mask & STATX_GEN)
> 		printf("Inode gen   : %xh\n", stx->st_gen);
> 
> +	if (stx->st_mask & STATX_WIN_ATTRS) {
> +		unsigned char bits;
> +		int loop, byte;
> +
> +		static char wattr_representation[32 + 1] =
> +			/* STATX_WIN_ATTR_ flags: */
> +			"????????"	/* 31-24	0x00000000-ff000000 */
> +			"??????N?"	/* 23-16	0x00000000-00ff0000 */
> +			"ieNocrst"	/* 15- 8	0x00000000-0000ff00 */
> +			"n?Ad?SHR"	/*  7- 0	0x00000000-000000ff */
> +			;
> +
> +		printf("Win attrs  : %08llx (",
> +		       (unsigned long long)stx->st_win_attrs);
> +		for (byte = 32 - 8; byte >= 0; byte -= 8) {
> +			bits = stx->st_win_attrs >> byte;
> +			for (loop = 7; loop >= 0; loop--) {
> +				int bit = byte + loop;
> +
> +				if (bits & 0x80)
> +					putchar(wattr_representation[31 - bit]);
> +				else
> +					putchar('-');
> +				bits <<= 1;
> +			}
> +			if (byte)
> +				putchar(' ');
> +		}
> +		printf(")\n");
> +	}
> +
> 	if (stx->st_information) {
> 		unsigned char bits;
> 		int loop, byte;
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


Cheers, Andreas





[toc] | [prev] | [next] | [standalone]


#1393789 — Re: [PATCH 5/6] statx: Make windows attributes available for CIFS, NTFS and FAT to use

FromDavid Howells <dhowells@redhat.com>
Date2016-05-03 22:30 +0200
SubjectRe: [PATCH 5/6] statx: Make windows attributes available for CIFS, NTFS and FAT to use
Message-ID<ruP7d-6xa-43@gated-at.bofh.it>
In reply to#1392556
Andreas Dilger <adilger@dilger.ca> wrote:

> > 	__u32	st_win_attrs;
> 
> It seems some of these flags are duplicated with the st_information field,
> and some are duplicate with FS_IOC_GETFLAGS values, and returning the same
> information in multiple ways is confusing.
>
> If these flags are part of the CIFS protocol,

They're part of the Windows API.  CIFS/SMB and NTFS have them at the same
values.

> and are directly usable by Samba then I can understand we wouldn't want to
> change them once in the kernel and then convert them back in userspace, but
> I'm a bit reluctant to have flags only for CIFS/NTFS/FAT that might also be
> useful for other filesystems.

Where said "other filesystems" have some support for Windows or OS/2 and have
bits defined that map directly in semantics, if not in value, to these bits.

JFS, for example, has IREADONLY, IHIDDEN, ISYSTEM, IDIRECTORY, IARCHIVE and
ISPARSE.

> Would we want to be able to get translated
> st_win_attrs flags in ext4 attrs when it is being exported by Samba?

Actually, I was thinking of proposing an ext4 patch that stored windows flags
in a separate word in the inode on disk.  There isn't sufficient bit space to
map all the windows flags to FS_IOC_GETFLAGS.  However, as you say, there is a
certain amount of overlap...

David

[toc] | [prev] | [next] | [standalone]


#1396392 — Re: [PATCH 5/6] statx: Make windows attributes available for CIFS, NTFS and FAT to use

FromChristoph Hellwig <hch@infradead.org>
Date2016-05-08 10:40 +0200
SubjectRe: [PATCH 5/6] statx: Make windows attributes available for CIFS, NTFS and FAT to use
Message-ID<rwspP-3md-1@gated-at.bofh.it>
In reply to#1391114
On Fri, Apr 29, 2016 at 01:58:14PM +0100, David Howells wrote:
> Make windows attributes available for CIFS, NTFS and FAT to use in the
> statx struct.  The attribute flags map directly by value to those in the
> CIFS PDU flags.  Some of these bits can also be used by JFS, UFS and HPFS.

Err, no way.  Not that I disagree that some of these might be useful,
but we should define our own set of flags, which would include the
generic part of the IOC_GETFLAGS flags amd whatever we want to add to
them.  And we should probably go for 64-bit flags while we're at it.

[toc] | [prev] | [next] | [standalone]


#1391130 — [PATCH 2/6] statx: AFS: Return enhanced file attributes

FromDavid Howells <dhowells@redhat.com>
Date2016-04-29 15:20 +0200
Subject[PATCH 2/6] statx: AFS: Return enhanced file attributes
Message-ID<rtguS-6Au-3@gated-at.bofh.it>
In reply to#1391088
Return enhanced file attributes from the AFS filesystem.  This includes the
following:

 (1) The data version number as st_version, setting STATX_VERSION.

 (2) STATX_INFO_AUTOMOUNT will be set on automount directories by virtue of
     S_AUTOMOUNT being set on the inode.  These are referrals to other
     volumes or other cells.

 (3) STATX_INFO_AUTODIR on a directory that does cell lookup for
     non-existent names and mounts them (typically mounted on /afs with -o
     autocell).  The resulting directories are marked STATX_INFO_FABRICATED
     as they do not actually exist in the mounted AFS directory.

 (4) Files, directories and symlinks accessed over AFS are marked
     STATX_INFO_REMOTE.  Local fake directories are marked
     STATX_INFO_FABRICATED.

 (5) STATX_INFO_NONSYSTEM_OWNERSHIP is set as the UID and GID retrieved
     from an AFS share may not be applicable on the system.

STATX_ATIME, STATX_CTIME and STATX_BLOCKS are cleared as AFS does not
support them.

Example output:

	[root@andromeda ~]# ./samples/statx/test-statx /afs
	statx(/afs) = 0
	results=7ef
	  Size: 2048            Blocks: 0          IO Block: 4096    directory
	Device: 00:25           Inode: 1           Links: 2
	Access: (0777/drwxrwxrwx)  Uid:     0   Gid:     0
	Access: 2006-05-07 00:21:15.000000000+0100
	Modify: 2006-05-07 00:21:15.000000000+0100
	Change: 2006-05-07 00:21:15.000000000+0100
	IO-blocksize: blksize=4096

Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/afs/inode.c |   24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/fs/afs/inode.c b/fs/afs/inode.c
index 86cc7264c21c..e9958d5e267e 100644
--- a/fs/afs/inode.c
+++ b/fs/afs/inode.c
@@ -72,9 +72,9 @@ static int afs_inode_map_status(struct afs_vnode *vnode, struct key *key)
 	inode->i_uid		= vnode->status.owner;
 	inode->i_gid		= GLOBAL_ROOT_GID;
 	inode->i_size		= vnode->status.size;
-	inode->i_ctime.tv_sec	= vnode->status.mtime_server;
-	inode->i_ctime.tv_nsec	= 0;
-	inode->i_atime		= inode->i_mtime = inode->i_ctime;
+	inode->i_mtime.tv_sec	= vnode->status.mtime_server;
+	inode->i_mtime.tv_nsec	= 0;
+	inode->i_atime		= inode->i_ctime = inode->i_mtime;
 	inode->i_blocks		= 0;
 	inode->i_generation	= vnode->fid.unique;
 	inode->i_version	= vnode->status.data_version;
@@ -375,8 +375,7 @@ error_unlock:
 /*
  * read the attributes of an inode
  */
-int afs_getattr(struct vfsmount *mnt, struct dentry *dentry,
-		      struct kstat *stat)
+int afs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
 {
 	struct inode *inode;
 
@@ -385,6 +384,21 @@ int afs_getattr(struct vfsmount *mnt, struct dentry *dentry,
 	_enter("{ ino=%lu v=%u }", inode->i_ino, inode->i_generation);
 
 	generic_fillattr(inode, stat);
+
+	stat->result_mask &= ~(STATX_ATIME | STATX_CTIME | STATX_BLOCKS);
+	stat->result_mask |= STATX_VERSION | STATX_GEN;
+	stat->version = inode->i_version;
+	stat->gen = inode->i_generation;
+
+	if (test_bit(AFS_VNODE_AUTOCELL, &AFS_FS_I(inode)->flags))
+		stat->information |= STATX_INFO_AUTODIR;
+
+	if (test_bit(AFS_VNODE_PSEUDODIR, &AFS_FS_I(inode)->flags))
+		stat->information |= STATX_INFO_FABRICATED;
+	else
+		stat->information |= STATX_INFO_REMOTE;
+
+	stat->information |= STATX_INFO_NONSYSTEM_OWNERSHIP;
 	return 0;
 }
 

[toc] | [prev] | [next] | [standalone]


#1391684

FromJeff Layton <jlayton@poochiereds.net>
Date2016-04-30 23:10 +0200
Message-ID<rtKjg-69D-5@gated-at.bofh.it>
In reply to#1391088
On Fri, 2016-04-29 at 13:57 +0100, David Howells wrote:
> Implement a new system call to provide enhanced file stats.  The patches can
> be found here:
> 
> 	http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=xstat
> 
> 
> ===========
> DESCRIPTION
> ===========
> 
> The first patch provides this new system call:
> 
> 	long ret = statx(int dfd,
> 			 const char *filename,
> 			 unsigned atflag,
> 			 unsigned mask,
> 			 struct statx *buffer);
> 
> This is an enhanced file stat function that provides a number of useful
> features, in summary:
> 
>  (1) More information: creation time, data version number, inode generation
>      number and flags.  A subset of these is available through a number of
>      filesystems (such as CIFS, NFS, AFS, Ext4 and BTRFS).
> 
>  (2) Lightweight stat (AT_NO_ATTR_SYNC): Ask for just those details of
>      interest, and allow a network fs to approximate anything not of
>      interest, without going to the server.
> 
>  (3) Heavyweight stat (AT_FORCE_ATTR_SYNC): Force a network fs to flush
>      buffers and go to the server, even if it thinks its cached attributes
>      are up to date.
> 
>  (4) Allow the filesystem to indicate what it can/cannot provide: A
>      filesystem can now say it doesn't support a standard stat feature if
>      that isn't available.
> 
>  (5) Make the fields a consistent size on all arches, and make them large.
> 
>  (6) Can be extended by using more request flags and using up the padding
>      space in the statx struct.
> 
> Note that no lstat() equivalent is required as that can be implemented
> through statx() with atflag == 0.  There is also no fstat() equivalent as
> that can be implemented through statx() with filename == NULL and the
> relevant fd passed as dfd.
> 
> 
> =======
> TESTING
> =======
> 
> A test program is added into samples/statx/ by the first patch.
> 
> David
> ---
> David Howells (6):
>       statx: Add a system call to make enhanced file info available
>       statx: AFS: Return enhanced file attributes
>       statx: Ext4: Return enhanced file attributes
>       statx: NFS: Return enhanced file attributes
>       statx: Make windows attributes available for CIFS, NTFS and FAT to use
>       statx: CIFS: Return enhanced attributes
> 
> 
>  arch/x86/entry/syscalls/syscall_32.tbl |    1 
>  arch/x86/entry/syscalls/syscall_64.tbl |    1 
>  fs/afs/inode.c                         |   24 ++-
>  fs/cifs/cifsfs.h                       |    4 
>  fs/cifs/cifsglob.h                     |    8 +
>  fs/cifs/dir.c                          |    2 
>  fs/cifs/inode.c                        |  117 +++++++++---
>  fs/exportfs/expfs.c                    |    4 
>  fs/ext4/ext4.h                         |    2 
>  fs/ext4/file.c                         |    2 
>  fs/ext4/inode.c                        |   30 +++
>  fs/ext4/namei.c                        |    2 
>  fs/ext4/symlink.c                      |    2 
>  fs/nfs/inode.c                         |   41 ++++
>  fs/stat.c                              |  306 +++++++++++++++++++++++++++++---
>  include/linux/fs.h                     |    5 -
>  include/linux/stat.h                   |   15 +-
>  include/linux/syscalls.h               |    4 
>  include/uapi/linux/fcntl.h             |    2 
>  include/uapi/linux/stat.h              |  135 ++++++++++++++
>  samples/Makefile                       |    2 
>  samples/statx/Makefile                 |   10 +
>  samples/statx/test-statx.c             |  274 +++++++++++++++++++++++++++++
>  23 files changed, 910 insertions(+), 83 deletions(-)
>  create mode 100644 samples/statx/Makefile
>  create mode 100644 samples/statx/test-statx.c
> 


I looked over the patchset and it looks fairly straightforward to me.

Are there things that I'd have probably done differently? Yes, but
nothing really sticks out to me as show-stopping and this has the
potential to be helpful in all sorts of ways.

I think we really ought to resist excessive bikeshedding this time
around. With the way the interface is designed, we should be able to
expand on it later if we want to add new attributes after the interface
itself is merged.

Reviewed-by: Jeff Layton <jlayton@poochiereds.net>

[toc] | [prev] | [next] | [standalone]


#1393559 — Re: [PATCH 1/6] statx: Add a system call to make enhanced file info available

FromDavid Howells <dhowells@redhat.com>
Date2016-05-03 18:00 +0200
SubjectRe: [PATCH 1/6] statx: Add a system call to make enhanced file info available
Message-ID<ruKTU-2jL-3@gated-at.bofh.it>
In reply to#1391088
Andreas Dilger <adilger@dilger.ca> wrote:

> > 	STATX_INFO_ENCRYPTED		File is encrypted
> 
> This flag overlaps with FS_ENCRYPT_FL that is encoded in the FS_IOC_GETFLAGS
> attributes.  Are the FS_* flags expected to be translated into STATX_INFO_*
> flags by each filesystem, or will they be partly duplicated in a separate
> "st_attrs" field added in the future?

I think that most of the FS_IOC_GETFLAGS flags are sufficiently specialised
that they aren't something the ordinary user would necessarily find to be of
interest, so I'm not sure that mapping all of them to STATX_INFO_* flags is
necessary.

That said, I think STATX_INFO_ENCRYPTED *is* usefully deployed here to tell
the user that the file or directory is encrypted and that the user will have
to unlock or provide a key to access it.

I'm also thinking that a STATX_INFO_NEED_AUTHENTICATION flag may be needed to
indicate that the user must authenticate in some way (probably only applicable
to network files) to be able to access the file.

David

[toc] | [prev] | [next] | [standalone]


#1394307

FromArnd Bergmann <arnd@arndb.de>
Date2016-05-04 15:50 +0200
Message-ID<rv5lF-4Ot-27@gated-at.bofh.it>
In reply to#1391088
On Friday 29 April 2016 13:57:36 David Howells wrote:
>                          struct statx *buffer);
> 
> This is an enhanced file stat function that provides a number of useful
> features, in summary:
> 
>  (1) More information: creation time, data version number, inode generation
>      number and flags.  A subset of these is available through a number of
>      filesystems (such as CIFS, NFS, AFS, Ext4 and BTRFS).
> 

I have a question about birthtime/creationtime: As we are gaining a way
to read this, should we also provide a way to update it using a new variant
of the utimensat syscall in order to have 'cp -a' create an identical copy,
or is the idea that this is defined as the time that is particular copy
of the inode was created?

I've discussed this with Deepa in the past, as she is driving the
convertion of the inode timestamps to timespec64 now, and we will
need a new version of utimensat for her work as well. I can see good
reasons either way (allowing updates of btime or disallowing them).

This should not hold up the statx syscall from getting merged as
soon as we can, but I'd like to know what everyone feels about that
question now that they are looking at the interface already.

	Arnd

[toc] | [prev] | [next] | [standalone]


#1395575

FromSteve French <smfrench@gmail.com>
Date2016-05-06 04:10 +0200
Message-ID<rvDnj-42h-7@gated-at.bofh.it>
In reply to#1394307
On Thu, May 5, 2016 at 5:54 PM, Steve French <smfrench@gmail.com> wrote:
> On Wed, May 4, 2016 at 8:46 AM, Arnd Bergmann <arnd@arndb.de> wrote:
>> On Friday 29 April 2016 13:57:36 David Howells wrote:
>>> struct statx *buffer);
>>>
>>> This is an enhanced file stat function that provides a number of useful
>>> features, in summary:
>>>
>>> (1) More information: creation time, data version number, inode
>>> generation
>>> number and flags. A subset of these is available through a number of
>>> filesystems (such as CIFS, NFS, AFS, Ext4 and BTRFS).
>>>
>>
>> I have a question about birthtime/creationtime: As we are gaining a way
>> to read this, should we also provide a way to update it using a new
>> variant
>> of the utimensat syscall in order to have 'cp -a' create an identical
>> copy,
>> or is the idea that this is defined as the time that is particular copy
>> of the inode was created?
>>
>> I've discussed this with Deepa in the past, as she is driving the
>> convertion of the inode timestamps to timespec64 now, and we will
>> need a new version of utimensat for her work as well. I can see good
>> reasons either way (allowing updates of btime or disallowing them).
>
It would help interop with Windows (and presumably Mac) if birth time can be
updated



-- 
Thanks,

Steve

[toc] | [prev] | [next] | [standalone]


#1397028

FromArnd Bergmann <arnd@arndb.de>
Date2016-05-09 15:10 +0200
Message-ID<rwT6G-6j0-11@gated-at.bofh.it>
In reply to#1395575
On Thursday 05 May 2016 21:00:18 Steve French wrote:
> On Thu, May 5, 2016 at 5:54 PM, Steve French <smfrench@gmail.com> wrote:
> > On Wed, May 4, 2016 at 8:46 AM, Arnd Bergmann <arnd@arndb.de> wrote:
> >> On Friday 29 April 2016 13:57:36 David Howells wrote:
> >>> struct statx *buffer);
> >>>
> >>> This is an enhanced file stat function that provides a number of useful
> >>> features, in summary:
> >>>
> >>> (1) More information: creation time, data version number, inode
> >>> generation
> >>> number and flags. A subset of these is available through a number of
> >>> filesystems (such as CIFS, NFS, AFS, Ext4 and BTRFS).
> >>>
> >>
> >> I have a question about birthtime/creationtime: As we are gaining a way
> >> to read this, should we also provide a way to update it using a new
> >> variant
> >> of the utimensat syscall in order to have 'cp -a' create an identical
> >> copy,
> >> or is the idea that this is defined as the time that is particular copy
> >> of the inode was created?
> >>
> >> I've discussed this with Deepa in the past, as she is driving the
> >> convertion of the inode timestamps to timespec64 now, and we will
> >> need a new version of utimensat for her work as well. I can see good
> >> reasons either way (allowing updates of btime or disallowing them).
> >
> It would help interop with Windows (and presumably Mac) if birth time can be
> updated

Ok, thanks. That is certainly a good reason in favor.

If nothing else comes up, I guess we can prepare a patch for a new
utimensat variant to do this and wait for more comments on that.

	Arnd

[toc] | [prev] | [next] | [standalone]


#1394774 — Re: [PATCH 1/6] statx: Add a system call to make enhanced file info available

FromDave Chinner <david@fromorbit.com>
Date2016-05-05 01:00 +0200
SubjectRe: [PATCH 1/6] statx: Add a system call to make enhanced file info available
Message-ID<rvdVV-4gE-45@gated-at.bofh.it>
In reply to#1391088
On Fri, Apr 29, 2016 at 01:57:43PM +0100, David Howells wrote:
>  (4) File creation time (st_btime*), data version (st_version), inode
>      generation number (st_gen).
> 
>      These will be returned if available whether the caller asked for them or
>      not.  The corresponding bits in st_mask will be set or cleared as
>      appropriate to indicate a valid value.

IMO, exposing the inode generation number to anyone is a potential
security problem because they are used in file handles.

Most file handles provided by filesystems are simply an encoding of
the inode number + generation number, plus maybe the ino+gen of the
parent dir if the NFS server is configured to do this. This makes it
trivial for an attacker to guess what the likely generation numbers
are going to be for inode numbers surrounding any given inode, hence
greatly reducing the search space for guessing valid file handles.

We've known this to be a problem for a long time - file handles are
not cryptographically secure, so exposing information like this by
default make guessing handles successfully almost trivial for many
filesystems.

In the latest XFS filesystem format, we randomise the generation
value during every inode allocation to make it hard to guess the
handle of adjacent inodes from an existing ino+gen pair, or even
from life time to life time of the same inode. We don't use a secure
random number generator (prandom_u32()) so it's still possible to
guess with enough trial and observation. However, it makes it
several orders of magnitude harder to guess and requires knowledge
of inode allocation order to guess correctly once the random number
sequence has been deduced and so makes brute force the only real
option for guessing a valid handle for an inode.

However, this is definitely a problem for the older format where
each cluster of inodes was initialised with the same seed at cluster
allocation time and the generation number was simply incremented for
each life time. Most filesystems use a similar method for seeding
and incrementing generation numbers, so once the generation numbers
are exposed it makes handles trivial to calculate successfully.

>      If the caller didn't ask for them, then they may be approximated.  For
>      example, NFS won't waste any time updating them from the server, unless
>      as a byproduct of updating something requested.

I would suggest that exposing them from the NFS server is something
we most definitely don't want to do because they are the only thing
that keeps remote users from guessing filehandles with ease....

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

[toc] | [prev] | [next] | [standalone]


#1394805 — Re: [PATCH 1/6] statx: Add a system call to make enhanced file info available

FromNeilBrown <nfbrown@novell.com>
Date2016-05-05 02:20 +0200
SubjectRe: [PATCH 1/6] statx: Add a system call to make enhanced file info available
Message-ID<rvfbj-5Sz-5@gated-at.bofh.it>
In reply to#1394774

[Multipart message — attachments visible in raw view] — view raw

On Thu, May 05 2016, Dave Chinner wrote:

> On Fri, Apr 29, 2016 at 01:57:43PM +0100, David Howells wrote:
>>  (4) File creation time (st_btime*), data version (st_version), inode
>>      generation number (st_gen).
>> 
>>      These will be returned if available whether the caller asked for them or
>>      not.  The corresponding bits in st_mask will be set or cleared as
>>      appropriate to indicate a valid value.
>
> IMO, exposing the inode generation number to anyone is a potential
> security problem because they are used in file handles.

"security through obscurity".  We have Kerberos working really nicely
for NFS these days.  Do we still care?

What if the generation number were only made available to "root"?  Would
that allay your concerns?
Would that still be useful?
We already have name_to_handle_at().  Exposing the generation number
could/should follow the same rules at that.  Or maybe the exposure of
each field should be guided by the filesystem, depending on (for
example) whether it is used to provide uniqueness to the filehandle.

>
>>      If the caller didn't ask for them, then they may be approximated.  For
>>      example, NFS won't waste any time updating them from the server, unless
>>      as a byproduct of updating something requested.
>
> I would suggest that exposing them from the NFS server is something
> we most definitely don't want to do because they are the only thing
> that keeps remote users from guessing filehandles with ease....

Given that the NFS protocol does not define a "generation number"
attribute, I think there is no risk for them being exposed from the NFS
server ... except implicitly within the filehandle of course.

NeilBrown

[toc] | [prev] | [next] | [standalone]


Page 1 of 3  [1] 2 3  Next page →

Back to top | Article view | linux.kernel


csiph-web