vfs:ceph: add support for new ceph_statx() interface to ceph vfs module
cover vfs:ceph: add support for new ceph_statx() interface to ceph vfs module
Posting as an RFC set as this should not be merged until the libcephfs interfaces are in place.
This patchset should give the samba vfs ceph module support for a real "birthtime" on files. It relies on a set of new interfaces being added to ceph in this pull request:
https://github.com/ceph/ceph/pull/10922
While that's being reviewed, I'd like to also put this set of patches out here to get some eyes on them. Does the new ceph_statx() interface seem ok? (Note that my ulterior motive here is to use this as a PoC that we can point at for a similar kernel system call).
Note that while the set should be bisectable, birthtime handling may be "iffy" in some of the interim points of the set, due to different calls fetching and setting it in different places. The end result should be consistent though.
I've also not given much thought to preserving birthtimes on "legacy" ceph filesystems that don't have this support but that may have had it set in the xattr. Opinions are welcome there. Should we try to do that somehow?
Jeff Layton (6):
vfs:ceph: add configure test for ceph_statx vfs:ceph: add init_stat_ex_from_ceph_statx vfs:ceph: convert cephwrap_stat to use ceph_statx vfs:ceph: change cephwrap_fstatx to use ceph_fstatx vfs:ceph: convert cephwrap_lstat to use ceph_statx vfs:ceph: allow vfs_ceph to set the btime using setattrx
source3/modules/vfs_ceph.c | 216 ++++++++++++++++++++++++++++++++++++++------- source3/wscript | 2 + 2 files changed, 185 insertions(+), 33 deletions(-)
Signature · 1 line
2.7.4
RFC PATCH 1/6 vfs:ceph: add configure test for ceph_statx
...so we can conditionally compile in its use.
--- source3/wscript | 2 ++ 1 file changed, 2 insertions(+)
source3/wscript +2 -0
@@ -1582,6 +1582,8 @@ main() { if conf.CHECK_HEADERS('cephfs/libcephfs.h', False, False, 'cephfs') and conf.CHECK_LIB('cephfs', shlib=True) and Options.options.with_cephfs: if Options.options.with_acl_support: conf.DEFINE('HAVE_CEPH', '1') + if conf.CHECK_FUNCS_IN('ceph_statx', 'cephfs', headers='cephfs/libcephfs.h'): + conf.DEFINE('HAVE_CEPH_STATX', '1') else: Logs.warn("ceph support disabled due to --without-acl-support") conf.undefine('HAVE_CEPH')
Signature · 1 line
2.7.4
RFC PATCH 2/6 vfs:ceph: add init_stat_ex_from_ceph_statx
In reply to Jeff LaytonAdd a helper function that will convert a ceph_statx structure to a stat_ex. The main difference is that we can now get a proper btime.
--- source3/modules/vfs_ceph.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
source3/modules/vfs_ceph.c +31 -0
@@ -535,6 +535,37 @@ static int cephwrap_fsync(struct vfs_handle_struct *handle, files_struct *fsp)WRAP_RETURN (result); } +#ifdef HAVE_CEPH_STATX +#define MINORBITS (20) +#define MINORMASK ((1U << MINORBITS) - 1) +#define MAJOR (dev) ((unsigned int) ((dev) >> MINORBITS)) +#define MINOR (dev) ((unsigned int) ((dev) & MINORMASK)) +#define MKDEV (ma,mi) (((ma) << MINORBITS) | (mi)) + +static void init_stat_ex_from_ceph_statx (struct stat_ex *dst,const struct ceph_statx *stx) +{ + dst->st_ex_dev =MKDEV (stx->stx_dev_major, stx->stx_dev_minor); + dst->st_ex_rdev =MKDEV (stx->stx_rdev_major, stx->stx_rdev_minor); + dst->st_ex_ino = stx->stx_ino; + dst->st_ex_mode = stx->stx_mode; + dst->st_ex_uid = stx->stx_uid; + dst->st_ex_gid = stx->stx_gid; + dst->st_ex_size = stx->stx_size; + dst->st_ex_nlink = stx->stx_nlink; + dst->st_ex_atime.tv_sec = stx->stx_atime; + dst->st_ex_atime.tv_nsec = stx->stx_atime_ns; + dst->st_ex_btime.tv_sec = stx->stx_btime; + dst->st_ex_btime.tv_nsec = stx->stx_btime_ns; + dst->st_ex_ctime.tv_sec = stx->stx_ctime; + dst->st_ex_ctime.tv_nsec = stx->stx_ctime_ns; + dst->st_ex_mtime.tv_sec = stx->stx_mtime; + dst->st_ex_mtime.tv_nsec = stx->stx_mtime_ns; + dst->st_ex_calculated_birthtime = false; + dst->st_ex_blksize = stx->stx_blksize; + dst->st_ex_blocks = stx->stx_blocks; +} +#endif /* HAVE_CEPH_STATX */ +static int cephwrap_stat (struct vfs_handle_struct *handle,struct smb_filename *smb_fname) {
Signature · 1 line
2.7.4
RFC PATCH 3/6 vfs:ceph: convert cephwrap_stat to use ceph_statx
In reply to Jeff Layton--- source3/modules/vfs_ceph.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-)
source3/modules/vfs_ceph.c +36 -1
@@ -564,7 +564,41 @@ static void init_stat_ex_from_ceph_statx(struct stat_ex *dst, const struct ceph_ dst->st_ex_blksize = stx->stx_blksize; dst->st_ex_blocks = stx->stx_blocks; } -#endif /* HAVE_CEPH_STATX */ + +static int cephwrap_stat (struct vfs_handle_struct *handle, +struct smb_filename *smb_fname) +{ +int result =-1 ; +struct ceph_statx stx; + +DEBUG (10 , ("[CEPH] stat(%p, %s)\n" , handle,smb_fname_str_dbg (smb_fname))); + +if (smb_fname->stream_name) { + errno =ENOENT ; +return result; + } + + result =ceph_statx (handle->data, smb_fname->base_name, &stx, +CEPH_STATX_BASIC_STATS |CEPH_STATX_BTIME ,0 ); +DEBUG (10 , ("[CEPH] statx(...) = %d\n" , result)); +if (result <0 ) { +WRAP_RETURN (result); + }else { +DEBUG (10 , ("[CEPH]\tstx = {dev = %llx/%llx, ino = %llu, mode = 0x%x, nlink = %llu, " +"uid = %d, gid = %d, rdev = %llx/%llx, size = %llu, blksize = %llu, " +"blocks = %llu, atime = %llu, mtime = %llu, ctime = %llu, btime = %llu}\n" , +llu (stx.stx_dev_major),llu (stx.stx_dev_minor),llu (stx.stx_ino), stx.stx_mode, +llu (stx.stx_nlink), stx.stx_uid, stx.stx_gid,llu (stx.stx_rdev_major), +llu (stx.stx_rdev_minor),llu (stx.stx_size),llu (stx.stx_blksize), +llu (stx.stx_blocks),llu (stx.stx_atime),llu (stx.stx_mtime),llu (stx.stx_ctime), +llu (stx.stx_btime))); + } +init_stat_ex_from_ceph_statx (&smb_fname->st, &stx); +DEBUG (10 , ("[CEPH] mode = 0x%x\n" , smb_fname->st.st_ex_mode)); +return result; +} + +#else /* HAVE_CEPH_STATX */ static int cephwrap_stat (struct vfs_handle_struct *handle,struct smb_filename *smb_fname)
@@ -597,6 +631,7 @@ static int cephwrap_stat(struct vfs_handle_struct *handle,DEBUG (10 , ("[CEPH] mode = 0x%x\n" , smb_fname->st.st_ex_mode)); return result; } +#endif /* HAVE_CEPH_STATX */ static int cephwrap_fstat (struct vfs_handle_struct *handle,files_struct *fsp,SMB_STRUCT_STAT *sbuf) {
Signature · 1 line
2.7.4
RFC PATCH 4/6 vfs:ceph: change cephwrap_fstatx to use ceph_fstatx
In reply to Jeff Layton--- source3/modules/vfs_ceph.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
source3/modules/vfs_ceph.c +27 -1
@@ -598,6 +598,32 @@ static int cephwrap_stat(struct vfs_handle_struct *handle,return result; } +static int cephwrap_fstat (struct vfs_handle_struct *handle,files_struct *fsp,SMB_STRUCT_STAT *sbuf) +{ +int result =-1 ; +struct ceph_statx stx; + +DEBUG (10 , ("[CEPH] fstat(%p, %d)\n" , handle, fsp->fh->fd)); + result =ceph_fstatx (handle->data, fsp->fh->fd, &stx, +CEPH_STATX_BASIC_STATS |CEPH_STATX_BTIME ,0 ); +DEBUG (10 , ("[CEPH] fstat(...) = %d\n" , result)); +if (result <0 ) { +WRAP_RETURN (result); + }else { +DEBUG (10 , ("[CEPH]\tstx = {dev = %llx/%llx, ino = %llu, mode = 0x%x, nlink = %llu, " +"uid = %d, gid = %d, rdev = %llx/%llx, size = %llu, blksize = %llu, " +"blocks = %llu, atime = %llu, mtime = %llu, ctime = %llu, btime = %llu}\n" , +llu (stx.stx_dev_major),llu (stx.stx_dev_minor),llu (stx.stx_ino), stx.stx_mode, +llu (stx.stx_nlink), stx.stx_uid, stx.stx_gid,llu (stx.stx_rdev_major), +llu (stx.stx_rdev_minor),llu (stx.stx_size),llu (stx.stx_blksize), +llu (stx.stx_blocks),llu (stx.stx_atime),llu (stx.stx_mtime),llu (stx.stx_ctime), +llu (stx.stx_btime))); + } +init_stat_ex_from_ceph_statx (sbuf, &stx); +DEBUG (10 , ("[CEPH] mode = 0x%x\n" , sbuf->st_ex_mode)); +return result; +} +#else /* HAVE_CEPH_STATX */ static int cephwrap_stat(struct vfs_handle_struct *handle,
@@ -631,7 +657,6 @@ static int cephwrap_stat(struct vfs_handle_struct *handle,DEBUG (10 , ("[CEPH] mode = 0x%x\n" , smb_fname->st.st_ex_mode));return result; } -#endif /* HAVE_CEPH_STATX */ static int cephwrap_fstat (struct vfs_handle_struct *handle,files_struct *fsp,SMB_STRUCT_STAT *sbuf) {
@@ -658,6 +683,7 @@ static int cephwrap_fstat(struct vfs_handle_struct *handle, files_struct *fsp, SDEBUG (10 , ("[CEPH] mode = 0x%x\n" , sbuf->st_ex_mode)); return result; } +#endif /* HAVE_CEPH_STATX */ static int cephwrap_lstat (struct vfs_handle_struct *handle,struct smb_filename *smb_fname)
Signature · 1 line
2.7.4
RFC PATCH 5/6 vfs:ceph: convert cephwrap_lstat to use ceph_statx
In reply to Jeff LaytonWe can use AT_SYMLINK_NOFOLLOW flag to get the right lookup semantics.
--- source3/modules/vfs_ceph.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
source3/modules/vfs_ceph.c +25 -1
@@ -624,6 +624,30 @@ static int cephwrap_fstat(struct vfs_handle_struct *handle, files_struct *fsp, Sreturn result; } +static int cephwrap_lstat (struct vfs_handle_struct *handle, +struct smb_filename *smb_fname) +{ +int result =-1 ; +struct ceph_statx stx; + +DEBUG (10 , ("[CEPH] lstat(%p, %s)\n" , handle,smb_fname_str_dbg (smb_fname))); + +if (smb_fname->stream_name) { + errno =ENOENT ; +return result; + } + + result =ceph_statx (handle->data, smb_fname->base_name, &stx, +CEPH_STATX_BASIC_STATS |CEPH_STATX_BTIME , +AT_SYMLINK_NOFOLLOW ); +DEBUG (10 , ("[CEPH] lstat(...) = %d\n" , result)); +if (result <0 ) { +WRAP_RETURN (result); + } +init_stat_ex_from_ceph_statx (&smb_fname->st, &stx); +return result; +} +#else /* HAVE_CEPH_STATX */ static int cephwrap_stat(struct vfs_handle_struct *handle,
@@ -683,7 +707,6 @@ static int cephwrap_fstat(struct vfs_handle_struct *handle, files_struct *fsp, SDEBUG (10 , ("[CEPH] mode = 0x%x\n" , sbuf->st_ex_mode));return result; } -#endif /* HAVE_CEPH_STATX */ static int cephwrap_lstat (struct vfs_handle_struct *handle,struct smb_filename *smb_fname)
@@ -708,6 +731,7 @@ static int cephwrap_lstat(struct vfs_handle_struct *handle, lp_fake_directory_create_times(SNUM(handle->conn))); return result; } +#endif /* HAVE_CEPH_STATX */ static int cephwrap_unlink (struct vfs_handle_struct *handle,const struct smb_filename *smb_fname)
Signature · 1 line
2.7.4
RFC PATCH 6/6 vfs:ceph: allow vfs_ceph to set the btime using setattrx
In reply to Jeff Layton...as well as the mtime and atime.
--- source3/modules/vfs_ceph.c | 100 ++++++++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 33 deletions(-)
source3/modules/vfs_ceph.c +67 -33
@@ -648,6 +648,40 @@ static int cephwrap_lstat(struct vfs_handle_struct *handle,return result; } +static int cephwrap_ntimes (struct vfs_handle_struct *handle, +const struct smb_filename *smb_fname, +struct smb_file_time *ft) +{ +struct ceph_statx stx = {0 }; +int result; +int mask =0 ; + +if (!null_timespec (ft->atime)) { + stx.stx_atime = ft->atime.tv_sec; + stx.stx_atime_ns = ft->atime.tv_nsec; + mask |=CEPH_SETATTR_ATIME ; + } +if (!null_timespec (ft->mtime)) { + stx.stx_mtime = ft->mtime.tv_sec; + stx.stx_mtime_ns = ft->mtime.tv_nsec; + mask |=CEPH_SETATTR_MTIME ; + } +if (!null_timespec (ft->create_time)) { + stx.stx_btime = ft->create_time.tv_sec; + stx.stx_btime_ns = ft->create_time.tv_nsec; + mask |=CEPH_SETATTR_BTIME ; + } + +if (!mask) +return 0 ; + + result =ceph_setattrx (handle->data, smb_fname->base_name, &stx, mask,0 ); +DEBUG (10 , ("[CEPH] ntimes(%p, %s, {%ld, %ld, %ld, %ld}) = %d\n" , handle,smb_fname_str_dbg (smb_fname), + ft->mtime.tv_sec, ft->atime.tv_sec, ft->ctime.tv_sec, + ft->create_time.tv_sec, result)); +return result; +} +#else /* HAVE_CEPH_STATX */ static int cephwrap_stat(struct vfs_handle_struct *handle,
@@ -731,6 +765,39 @@ static int cephwrap_lstat(struct vfs_handle_struct *handle, lp_fake_directory_create_times(SNUM(handle->conn)));return result; } + +static int cephwrap_ntimes (struct vfs_handle_struct *handle, +const struct smb_filename *smb_fname, +struct smb_file_time *ft) +{ +struct utimbuf buf; +int result; + +if (null_timespec (ft->atime)) { + buf.actime = smb_fname->st.st_ex_atime.tv_sec; + }else { + buf.actime = ft->atime.tv_sec; + } +if (null_timespec (ft->mtime)) { + buf.modtime = smb_fname->st.st_ex_mtime.tv_sec; + }else { + buf.modtime = ft->mtime.tv_sec; + } +if (!null_timespec (ft->create_time)) { +set_create_timespec_ea (handle->conn, smb_fname, + ft->create_time); + } +if (buf.actime == smb_fname->st.st_ex_atime.tv_sec && + buf.modtime == smb_fname->st.st_ex_mtime.tv_sec) { +return 0 ; + } + + result =ceph_utime (handle->data, smb_fname->base_name, &buf); +DEBUG (10 , ("[CEPH] ntimes(%p, %s, {%ld, %ld, %ld, %ld}) = %d\n" , handle,smb_fname_str_dbg (smb_fname), + ft->mtime.tv_sec, ft->atime.tv_sec, ft->ctime.tv_sec, + ft->create_time.tv_sec, result)); +return result; +}#endif /* HAVE_CEPH_STATX */ static int cephwrap_unlink(struct vfs_handle_struct *handle,
@@ -885,39 +952,6 @@ static char *cephwrap_getwd(struct vfs_handle_struct *handle)return SMB_STRDUP (cwd); } -static int cephwrap_ntimes (struct vfs_handle_struct *handle, -const struct smb_filename *smb_fname, -struct smb_file_time *ft) -{ -struct utimbuf buf; -int result; - -if (null_timespec (ft->atime)) { - buf.actime = smb_fname->st.st_ex_atime.tv_sec; - }else { - buf.actime = ft->atime.tv_sec; - } -if (null_timespec (ft->mtime)) { - buf.modtime = smb_fname->st.st_ex_mtime.tv_sec; - }else { - buf.modtime = ft->mtime.tv_sec; - } -if (!null_timespec (ft->create_time)) { -set_create_timespec_ea (handle->conn, smb_fname, - ft->create_time); - } -if (buf.actime == smb_fname->st.st_ex_atime.tv_sec && - buf.modtime == smb_fname->st.st_ex_mtime.tv_sec) { -return 0 ; - } - - result =ceph_utime (handle->data, smb_fname->base_name, &buf); -DEBUG (10 , ("[CEPH] ntimes(%p, %s, {%ld, %ld, %ld, %ld}) = %d\n" , handle,smb_fname_str_dbg (smb_fname), - ft->mtime.tv_sec, ft->atime.tv_sec, ft->ctime.tv_sec, - ft->create_time.tv_sec, result)); -return result; -} -static int strict_allocate_ftruncate (struct vfs_handle_struct *handle,files_struct *fsp,off_t len) {off_t space_to_write;
Signature · 1 line
2.7.4