[v2,3/5] ceph: add ceph.snap.btime vxattr
diff mbox series

Message ID 20190416172606.26037-4-ddiss@suse.de
State New
Headers show
Series
  • ceph: add snapshot creation time vxattr
Related show

Commit Message

David Disseldorp April 16, 2019, 5:26 p.m. UTC
The ceph.snap.btime virtual xattr provides the snapshot creation (birth)
time in $secs.$nsecs format.

Link: https://tracker.ceph.com/issues/38838
Signed-off-by: David Disseldorp <ddiss@suse.de>
---
 fs/ceph/xattr.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

Comments

Yan, Zheng April 18, 2019, 2:57 a.m. UTC | #1
On Wed, Apr 17, 2019 at 1:26 AM David Disseldorp <ddiss@suse.de> wrote:
>
> The ceph.snap.btime virtual xattr provides the snapshot creation (birth)
> time in $secs.$nsecs format.
>
> Link: https://tracker.ceph.com/issues/38838
> Signed-off-by: David Disseldorp <ddiss@suse.de>
> ---
>  fs/ceph/xattr.c | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
>
> diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
> index 2cbb9c239183..0bdc7c715a42 100644
> --- a/fs/ceph/xattr.c
> +++ b/fs/ceph/xattr.c
> @@ -273,6 +273,19 @@ static size_t ceph_vxattrcb_quota_max_files(struct ceph_inode_info *ci,
>         return snprintf(val, size, "%llu", ci->i_max_files);
>  }
>
> +/* snapshots */
> +static bool ceph_vxattrcb_snap_btime_exists(struct ceph_inode_info *ci)
> +{
> +       return (ci->i_snap_btime.tv_sec != 0 && ci->i_snap_btime.tv_nsec != 0);

this should be return (ci->i_snap_btime.tv_sec != 0 ||
ci->i_snap_btime.tv_nsec != 0);

> +}
> +
> +static size_t ceph_vxattrcb_snap_btime(struct ceph_inode_info *ci, char *val,
> +                                      size_t size)
> +{
> +       return snprintf(val, size, "%lld.09%ld", ci->i_snap_btime.tv_sec,
> +                       ci->i_snap_btime.tv_nsec);
> +}
> +
>  #define CEPH_XATTR_NAME(_type, _name)  XATTR_CEPH_PREFIX #_type "." #_name
>  #define CEPH_XATTR_NAME2(_type, _name, _name2) \
>         XATTR_CEPH_PREFIX #_type "." #_name "." #_name2
> @@ -341,6 +354,13 @@ static struct ceph_vxattr ceph_dir_vxattrs[] = {
>         },
>         XATTR_QUOTA_FIELD(quota, max_bytes),
>         XATTR_QUOTA_FIELD(quota, max_files),
> +       {
> +               .name = "ceph.snap.btime",
> +               .name_size = sizeof("ceph.snap.btime"),
> +               .getxattr_cb = ceph_vxattrcb_snap_btime,
> +               .exists_cb = ceph_vxattrcb_snap_btime_exists,
> +               .flags = VXATTR_FLAG_READONLY,
> +       },
>         { .name = NULL, 0 }     /* Required table terminator */
>  };
>  static size_t ceph_dir_vxattrs_name_size;      /* total size of all names */
> @@ -360,6 +380,13 @@ static struct ceph_vxattr ceph_file_vxattrs[] = {
>         XATTR_LAYOUT_FIELD(file, layout, object_size),
>         XATTR_LAYOUT_FIELD(file, layout, pool),
>         XATTR_LAYOUT_FIELD(file, layout, pool_namespace),
> +       {
> +               .name = "ceph.snap.btime",
> +               .name_size = sizeof("ceph.snap.btime"),
> +               .getxattr_cb = ceph_vxattrcb_snap_btime,
> +               .exists_cb = ceph_vxattrcb_snap_btime_exists,
> +               .flags = VXATTR_FLAG_READONLY,
> +       },
>         { .name = NULL, 0 }     /* Required table terminator */
>  };
>  static size_t ceph_file_vxattrs_name_size;     /* total size of all names */
> --
> 2.16.4
>
David Disseldorp April 18, 2019, 9:27 a.m. UTC | #2
On Thu, 18 Apr 2019 10:57:14 +0800, Yan, Zheng wrote:

> > +static bool ceph_vxattrcb_snap_btime_exists(struct ceph_inode_info *ci)
> > +{
> > +       return (ci->i_snap_btime.tv_sec != 0 && ci->i_snap_btime.tv_nsec != 0);  
> 
> this should be return (ci->i_snap_btime.tv_sec != 0 ||
> ci->i_snap_btime.tv_nsec != 0);

Good catch, will fix and resend.
FWIW, the libcephfs changes use !in->snap_btime.is_zero(), so don't
carry this error.

Cheers, David

Patch
diff mbox series

diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c
index 2cbb9c239183..0bdc7c715a42 100644
--- a/fs/ceph/xattr.c
+++ b/fs/ceph/xattr.c
@@ -273,6 +273,19 @@  static size_t ceph_vxattrcb_quota_max_files(struct ceph_inode_info *ci,
 	return snprintf(val, size, "%llu", ci->i_max_files);
 }
 
+/* snapshots */
+static bool ceph_vxattrcb_snap_btime_exists(struct ceph_inode_info *ci)
+{
+	return (ci->i_snap_btime.tv_sec != 0 && ci->i_snap_btime.tv_nsec != 0);
+}
+
+static size_t ceph_vxattrcb_snap_btime(struct ceph_inode_info *ci, char *val,
+				       size_t size)
+{
+	return snprintf(val, size, "%lld.09%ld", ci->i_snap_btime.tv_sec,
+			ci->i_snap_btime.tv_nsec);
+}
+
 #define CEPH_XATTR_NAME(_type, _name)	XATTR_CEPH_PREFIX #_type "." #_name
 #define CEPH_XATTR_NAME2(_type, _name, _name2)	\
 	XATTR_CEPH_PREFIX #_type "." #_name "." #_name2
@@ -341,6 +354,13 @@  static struct ceph_vxattr ceph_dir_vxattrs[] = {
 	},
 	XATTR_QUOTA_FIELD(quota, max_bytes),
 	XATTR_QUOTA_FIELD(quota, max_files),
+	{
+		.name = "ceph.snap.btime",
+		.name_size = sizeof("ceph.snap.btime"),
+		.getxattr_cb = ceph_vxattrcb_snap_btime,
+		.exists_cb = ceph_vxattrcb_snap_btime_exists,
+		.flags = VXATTR_FLAG_READONLY,
+	},
 	{ .name = NULL, 0 }	/* Required table terminator */
 };
 static size_t ceph_dir_vxattrs_name_size;	/* total size of all names */
@@ -360,6 +380,13 @@  static struct ceph_vxattr ceph_file_vxattrs[] = {
 	XATTR_LAYOUT_FIELD(file, layout, object_size),
 	XATTR_LAYOUT_FIELD(file, layout, pool),
 	XATTR_LAYOUT_FIELD(file, layout, pool_namespace),
+	{
+		.name = "ceph.snap.btime",
+		.name_size = sizeof("ceph.snap.btime"),
+		.getxattr_cb = ceph_vxattrcb_snap_btime,
+		.exists_cb = ceph_vxattrcb_snap_btime_exists,
+		.flags = VXATTR_FLAG_READONLY,
+	},
 	{ .name = NULL, 0 }	/* Required table terminator */
 };
 static size_t ceph_file_vxattrs_name_size;	/* total size of all names */