From 6523ab4f91413091c75c0741a4c470e47bc9927f Mon Sep 17 00:00:00 2001 From: Varsha Rao Date: Tue, 28 Jan 2020 15:14:29 +0530 Subject: [PATCH] cephfs-shell: Add setxattr command Fixes: https://tracker.ceph.com/issues/42530 Signed-off-by: Varsha Rao --- src/tools/cephfs/cephfs-shell | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/tools/cephfs/cephfs-shell b/src/tools/cephfs/cephfs-shell index 01141027c26..a7349b809a9 100755 --- a/src/tools/cephfs/cephfs-shell +++ b/src/tools/cephfs/cephfs-shell @@ -1410,6 +1410,28 @@ class CephFSShell(Cmd): perror(e) self.exit_code = e.get_error_code() + setxattr_parser = argparse.ArgumentParser( + description='Set extended attribute for a file') + setxattr_parser.add_argument('path', type=str, action=path_to_bytes, help='Name of the file') + setxattr_parser.add_argument('name', type=str, help='Extended attribute name') + setxattr_parser.add_argument('value', type=str, help='Extended attribute value') + + @with_argparser(setxattr_parser) + def do_setxattr(self, args): + """ + Set extended attribute for a file + """ + val_bytes = to_bytes(args.value) + name_bytes = to_bytes(args.name) + try: + cephfs.setxattr(args.path, name_bytes, val_bytes, os.XATTR_CREATE) + poutput('{} is successfully set to {}'.format(args.name, args.value)) + except libcephfs.ObjectExists: + cephfs.setxattr(args.path, name_bytes, val_bytes, os.XATTR_REPLACE) + poutput('{} is successfully reset to {}'.format(args.name, args.value)) + except libcephfs.Error as e: + perror(e) + self.exit_code = e.get_error_code() ####################################################### # -- 2.39.5