From 77d0268cb28de75fd4410a4cb3df2e3297a0df1b Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Thu, 9 Feb 2017 15:47:02 -0800 Subject: [PATCH] Add printing xattrs For now we only print the xattr names, not the values. Signed-off-by: Zach Brown --- utils/src/format.h | 37 +++++++++++++++++++++++++------------ utils/src/print.c | 34 +++++++++++++++------------------- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/utils/src/format.h b/utils/src/format.h index 0d5edcfc..83c4d5d8 100644 --- a/utils/src/format.h +++ b/utils/src/format.h @@ -231,9 +231,7 @@ struct scoutfs_key { * have to stress about cleverly allocating the types. */ #define SCOUTFS_INODE_KEY 1 -#define SCOUTFS_XATTR_KEY 2 -#define SCOUTFS_XATTR_NAME_HASH_KEY 3 -#define SCOUTFS_XATTR_VAL_HASH_KEY 4 +#define SCOUTFS_XATTR_KEY 3 #define SCOUTFS_DIRENT_KEY 5 #define SCOUTFS_READDIR_KEY 6 #define SCOUTFS_LINK_BACKREF_KEY 7 @@ -286,6 +284,23 @@ struct scoutfs_data_key { __be64 block; } __packed; +/* value is each item's part of the full xattr value for the off/len */ +struct scoutfs_xattr_key { + __u8 type; + __be64 ino; + __u8 name[0]; +} __packed; + +struct scoutfs_xattr_key_footer { + __u8 null; + __u8 part; +} __packed; + +struct scoutfs_xattr_val_header { + __le16 part_len; + __u8 last_part; +} __packed; + struct scoutfs_btree_root { u8 height; struct scoutfs_block_ref ref; @@ -447,6 +462,13 @@ struct scoutfs_dirent { /* S32_MAX avoids the (int) sign bit and might avoid sloppy bugs */ #define SCOUTFS_LINK_MAX S32_MAX +#define SCOUTFS_XATTR_MAX_NAME_LEN 255 +#define SCOUTFS_XATTR_MAX_SIZE 65536 +#define SCOUTFS_XATTR_PART_SIZE \ + (SCOUTFS_BLOCK_SIZE - sizeof(struct scoutfs_xattr_val_header)) +#define SCOUTFS_XATTR_MAX_PARTS \ + DIV_ROUND_UP(SCOUTFS_XATTR_MAX_SIZE, SCOUTFS_XATTR_PART_SIZE) + /* * We only use 31 bits for readdir positions so that we don't confuse * old signed 32bit f_pos applications or those on the other side of @@ -470,15 +492,6 @@ enum { SCOUTFS_DT_WHT, }; -#define SCOUTFS_MAX_XATTR_LEN 255 -#define SCOUTFS_XATTR_NAME_HASH_MASK 7ULL - -struct scoutfs_xattr { - __u8 name_len; - __u8 value_len; - __u8 name[0]; -} __packed; - struct scoutfs_extent { __le64 blkno; __le64 len; diff --git a/utils/src/print.c b/utils/src/print.c index 2f98717f..ac8a5975 100644 --- a/utils/src/print.c +++ b/utils/src/print.c @@ -111,25 +111,6 @@ static void print_orphan(void *key, int key_len, void *val, int val_len) printf(" orphan: ino %llu\n", be64_to_cpu(okey->ino)); } -#if 0 - -static void print_xattr(struct scoutfs_xattr *xat) -{ - /* XXX check lengths */ - - printf(" xattr: name %.*s val_len %u\n", - xat->name_len, xat->name, xat->value_len); -} - -static void print_xattr_val_hash(__le64 *refcount) -{ - /* XXX check lengths */ - - printf(" xattr_val_hash: refcount %llu\n", - le64_to_cpu(*refcount)); -} -#endif - static u8 *global_printable_name(u8 *name, int name_len) { static u8 name_buf[SCOUTFS_NAME_LEN + 1]; @@ -143,6 +124,20 @@ static u8 *global_printable_name(u8 *name, int name_len) return name_buf; } +static void print_xattr(void *key, int key_len, void *val, int val_len) +{ + struct scoutfs_xattr_key *xkey = key; + struct scoutfs_xattr_key_footer *foot = key + key_len - sizeof(*foot); + struct scoutfs_xattr_val_header *vh = val; + unsigned int name_len = key_len - sizeof(*xkey) - sizeof(*foot); + u8 *name = global_printable_name(xkey->name, name_len); + + printf(" xattr: ino %llu part %u part_len %u last_part %u\n" + " name %s\n", + be64_to_cpu(xkey->ino), foot->part, le16_to_cpu(vh->part_len), + vh->last_part, name); +} + static void print_dirent(void *key, int key_len, void *val, int val_len) { struct scoutfs_dirent_key *dkey = key; @@ -213,6 +208,7 @@ typedef void (*print_func_t)(void *key, int key_len, void *val, int val_len); static print_func_t printers[] = { [SCOUTFS_INODE_KEY] = print_inode, + [SCOUTFS_XATTR_KEY] = print_xattr, [SCOUTFS_ORPHAN_KEY] = print_orphan, [SCOUTFS_DIRENT_KEY] = print_dirent, [SCOUTFS_READDIR_KEY] = print_readdir,