Skip to content

Commit dce2f47

Browse files
committed
Linux 4.11 compat: statx support
Linux 4.11 added a new statx system call that allows us to expose crtime as btime. We do this by caching crtime in the znode to match how atime, ctime and mtime are cached in the inode. statx also introduced a new way of reporting whether the immutable, append and nodump bits have been set. It adds support for reporting compression and encryption, but the semantics on other filesystems is not just to report compression/encryption, but to allow it to be turned on/off at the file level. We do not support that. We could implement semantics where we refuse to allow user modification of the bit, but we would need to do a dnode_hold() in zfs_znode_alloc() to find out encryption/compression information. That would introduce locking that will have a minor (although unmeasured) performance cost. It also would be inferior to zdb, which reports far more detailed information. We therefore omit reporting of encryption/compression through statx in favor of recommending that users interested in such information use zdb. Signed-off-by: Richard Yao <[email protected]> Closes #8507
1 parent ca6c7a9 commit dce2f47

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

include/sys/zfs_znode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ typedef struct znode {
216216
boolean_t z_is_mapped; /* are we mmap'ed */
217217
boolean_t z_is_ctldir; /* are we .zfs entry */
218218
boolean_t z_is_stale; /* are we stale due to rollback? */
219+
uint64_t z_crtime[2]; /* creation/birth time (cached) */
219220
struct inode z_inode; /* generic vfs inode */
220221
} znode_t;
221222

module/zfs/zfs_znode.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_buf_t *db, int blksz,
540540
uint64_t z_uid, z_gid;
541541
uint64_t atime[2], mtime[2], ctime[2];
542542
uint64_t projid = ZFS_DEFAULT_PROJID;
543-
sa_bulk_attr_t bulk[11];
543+
sa_bulk_attr_t bulk[12];
544544
int count = 0;
545545

546546
ASSERT(zfsvfs != NULL);
@@ -582,6 +582,8 @@ zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_buf_t *db, int blksz,
582582
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL, &atime, 16);
583583
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, &mtime, 16);
584584
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, &ctime, 16);
585+
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CRTIME(zfsvfs), NULL,
586+
&zp->z_crtime[0], 16);
585587

586588
if (sa_bulk_lookup(zp->z_sa_hdl, bulk, count) != 0 || tmp_gen == 0 ||
587589
(dmu_objset_projectquota_enabled(zfsvfs->z_os) &&

module/zfs/zpl_inode.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ zpl_getattr_impl(const struct path *path, struct kstat *stat, u32 request_mask,
345345
{
346346
int error;
347347
fstrans_cookie_t cookie;
348+
struct inode *ip = path->dentry->d_inode;
348349

349350
cookie = spl_fstrans_mark();
350351

@@ -353,6 +354,30 @@ zpl_getattr_impl(const struct path *path, struct kstat *stat, u32 request_mask,
353354
*/
354355

355356
error = -zfs_getattr_fast(path->dentry->d_inode, stat);
357+
358+
#ifdef STATX_BTIME
359+
ZFS_TIME_DECODE(&stat->btime, ITOZ(ip)->z_crtime);
360+
stat->result_mask |= STATX_BTIME;
361+
#endif
362+
363+
#ifdef STATX_ATTR_IMMUTABLE
364+
if (zfs_flags & ZFS_IMMUTABLE)
365+
stat->attributes |= STATX_ATTR_IMMUTABLE;
366+
stat->result_mask |= STATX_ATTR_IMMUTABLE;
367+
#endif
368+
369+
#ifdef STATX_ATTR_APPEND
370+
if (zfs_flags & ZFS_APPENDONLY)
371+
stat->attributes |= STATX_ATTR_APPEND;
372+
stat->result_mask |= STATX_ATTR_APPEND;
373+
#endif
374+
375+
#ifdef STATX_ATTR_NODUMP
376+
if (zfs_flags & ZFS_NODUMP)
377+
stat->attributes |= STATX_ATTR_NODUMP;
378+
stat->result_mask |= STATX_ATTR_NODUMP;
379+
#endif
380+
356381
spl_fstrans_unmark(cookie);
357382
ASSERT3S(error, <=, 0);
358383

0 commit comments

Comments
 (0)