From: Jeremy Allison Date: Wed, 23 Jun 2021 17:58:40 +0000 (-0700) Subject: s3: VFS: ceph_snapshots: Add ceph_snap_get_btime_fsp(). X-Git-Tag: tevent-0.11.0~182 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe9575c88f048ac760a33fd5f65c18e8f2714e70;p=thirdparty%2Fsamba.git s3: VFS: ceph_snapshots: Add ceph_snap_get_btime_fsp(). Handle-based copy of ceph_snap_get_btime(). Uses SMB_VFS_NEXT_FGETXATTR() instead of SMB_VFS_NEXT_GETXATTR(). Commented out as nothing uses it yet. This will change shortly. Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme --- diff --git a/source3/modules/vfs_ceph_snapshots.c b/source3/modules/vfs_ceph_snapshots.c index be9b2dd1aa6..1b5322475dd 100644 --- a/source3/modules/vfs_ceph_snapshots.c +++ b/source3/modules/vfs_ceph_snapshots.c @@ -113,6 +113,76 @@ static int ceph_snap_get_btime(struct vfs_handle_struct *handle, return 0; } +#if 0 +static int ceph_snap_get_btime_fsp(struct vfs_handle_struct *handle, + struct files_struct *fsp, + time_t *_snap_secs) +{ + int ret; + char snap_btime[33]; + char *s = NULL; + char *endptr = NULL; + struct timespec snap_timespec; + int err; + + ret = SMB_VFS_NEXT_FGETXATTR(handle, + fsp, + CEPH_SNAP_BTIME_XATTR, + snap_btime, + sizeof(snap_btime)); + if (ret < 0) { + DBG_ERR("failed to get %s xattr: %s\n", + CEPH_SNAP_BTIME_XATTR, strerror(errno)); + return -errno; + } + + if (ret == 0 || ret >= sizeof(snap_btime) - 1) { + return -EINVAL; + } + + /* ensure zero termination */ + snap_btime[ret] = '\0'; + + /* format is sec.nsec */ + s = strchr(snap_btime, '.'); + if (s == NULL) { + DBG_ERR("invalid %s xattr value: %s\n", + CEPH_SNAP_BTIME_XATTR, snap_btime); + return -EINVAL; + } + + /* First component is seconds, extract it */ + *s = '\0'; + snap_timespec.tv_sec = smb_strtoull(snap_btime, + &endptr, + 10, + &err, + SMB_STR_FULL_STR_CONV); + if (err != 0) { + return -err; + } + + /* second component is nsecs */ + s++; + snap_timespec.tv_nsec = smb_strtoul(s, + &endptr, + 10, + &err, + SMB_STR_FULL_STR_CONV); + if (err != 0) { + return -err; + } + + /* + * >> 30 is a rough divide by ~10**9. No need to be exact, as @GMT + * tokens only offer 1-second resolution (while twrp is nsec). + */ + *_snap_secs = snap_timespec.tv_sec + (snap_timespec.tv_nsec >> 30); + + return 0; +} +#endif + /* * XXX Ceph snapshots can be created with sub-second granularity, which means * that multiple snapshots may be mapped to the same @GMT- label.