]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: VFS: ceph_snapshots: Add ceph_snap_get_btime_fsp().
authorJeremy Allison <jra@samba.org>
Wed, 23 Jun 2021 17:58:40 +0000 (10:58 -0700)
committerRalph Boehme <slow@samba.org>
Fri, 25 Jun 2021 15:53:31 +0000 (15:53 +0000)
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 <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/modules/vfs_ceph_snapshots.c

index be9b2dd1aa67b4f6621b49316d5b500f0641e4de..1b5322475dd3ff5c0943fafa5d227da7e436e096 100644 (file)
@@ -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.