Whamcloud - gitweb
EX-2579 pcc: support a flatter HSM archive format
authorQian Yingjin <qian@ddn.com>
Thu, 29 Apr 2021 13:10:05 +0000 (21:10 +0800)
committerLi Xi <lixi@ddn.com>
Sat, 5 Jun 2021 15:42:36 +0000 (15:42 +0000)
Add versioning (v1 and V2) to the HSM (PCC) archive format (directory
layout):
v1: (oid & 0xffff)/-/-/-/-/-/FID
v2: ((oid ^ seq) & 0xffff)/FID

v1 is the original layout and the default. v2 is the new layout which
should be selected for new installs.

Signed-off-by: Qian Yingjin <qian@ddn.com>
Change-Id: If660f3cf4c02469bb23e65a44f86f0346367adf6
Reviewed-on: https://review.whamcloud.com/43493
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Feng, Lei <flei@whamcloud.com>
Reviewed-by: Li Xi <lixi@ddn.com>
lustre/include/uapi/linux/lustre/lustre_user.h
lustre/llite/pcc.c
lustre/llite/pcc.h
lustre/tests/sanity-pcc.sh
lustre/utils/libhsm_scanner.c

index 86a4f0d..964013c 100644 (file)
@@ -2713,15 +2713,24 @@ static inline const char *pcc_type2string(enum lu_pcc_type type)
 #define PCC_YAML_AUTOCACHE     "autocache"
 
 enum hsmtool_type {
-       HSMTOOL_UNKNOWN = 0,
-       HSMTOOL_POSIX   = 1,
+       HSMTOOL_UNKNOWN         = 0,
+       /*
+        * v1 (original) using 6 directories (oid & 0xffff)/-/-/-/-/-/FID.
+        * Places only one FID per directory. See ct_path_archive() below.
+        */
+       HSMTOOL_POSIX_V1        = 1,
+       /* v2 using (OID & 0xffff)^(SEQ & 0xffff)/FID. */
+       HSMTOOL_POSIX_V2        = 2,
+       HSMTOOL_DEFAULT         = HSMTOOL_POSIX_V2,
 };
 
 static inline const char *hsmtool_type2string(enum hsmtool_type type)
 {
        switch (type) {
-       case HSMTOOL_POSIX:
-               return "posix";
+       case HSMTOOL_POSIX_V1:
+               return "posix_v1";
+       case HSMTOOL_POSIX_V2:
+               return "posix_v2";
        default:
                return "unknown";
        }
@@ -2730,7 +2739,11 @@ static inline const char *hsmtool_type2string(enum hsmtool_type type)
 static inline enum hsmtool_type hsmtool_string2type(const char *str)
 {
        if (strcmp(str, "posix") == 0)
-               return HSMTOOL_POSIX;
+               return HSMTOOL_DEFAULT;
+       if (strcmp(str, "posix_v1") == 0)
+               return HSMTOOL_POSIX_V1;
+       if (strcmp(str, "posix_v2") == 0)
+               return HSMTOOL_POSIX_V2;
 
        return HSMTOOL_UNKNOWN;
 }
index b80259e..0fb8875 100644 (file)
@@ -704,6 +704,11 @@ pcc_parse_value_pair(struct pcc_cmd *cmd, char *buffer)
                        cmd->u.pccc_add.pccc_flags |= PCC_DATASET_PROJ_QUOTA;
                else
                        cmd->u.pccc_add.pccc_flags &= ~PCC_DATASET_PROJ_QUOTA;
+       } else if (strcmp(key, PCC_YAML_HSMTOOL) == 0) {
+               cmd->u.pccc_add.pccc_hsmtool_type = hsmtool_string2type(val);
+               if (cmd->u.pccc_add.pccc_hsmtool_type != HSMTOOL_POSIX_V1 &&
+                   cmd->u.pccc_add.pccc_hsmtool_type != HSMTOOL_POSIX_V2)
+                       return -EINVAL;
        } else {
                return -EINVAL;
        }
@@ -720,6 +725,7 @@ pcc_parse_value_pairs(struct pcc_cmd *cmd, char *buffer)
 
        switch (cmd->pccc_cmd) {
        case PCC_ADD_DATASET:
+               cmd->u.pccc_add.pccc_hsmtool_type = HSMTOOL_UNKNOWN;
                /* Enable these features by default */
                cmd->u.pccc_add.pccc_flags |= PCC_DATASET_AUTO_ATTACH |
                                              PCC_DATASET_MMAP_CONV |
@@ -1008,6 +1014,9 @@ pcc_dataset_flags_check(struct pcc_super *super, struct pcc_cmd *cmd)
            cmd->u.pccc_add.pccc_flags & PCC_DATASET_ROPCC)
                cmd->u.pccc_add.pccc_roid = cmd->u.pccc_add.pccc_rwid;
 
+       if (cmd->u.pccc_add.pccc_hsmtool_type == HSMTOOL_UNKNOWN)
+                       cmd->u.pccc_add.pccc_hsmtool_type = HSMTOOL_DEFAULT;
+
        return 0;
 }
 
@@ -1044,8 +1053,8 @@ pcc_dataset_add(struct pcc_super *super, struct pcc_cmd *cmd)
        dataset->pccd_rwid = cmd->u.pccc_add.pccc_rwid;
        dataset->pccd_roid = cmd->u.pccc_add.pccc_roid;
        dataset->pccd_flags = cmd->u.pccc_add.pccc_flags;
+       dataset->pccd_hsmtool_type = cmd->u.pccc_add.pccc_hsmtool_type;
        atomic_set(&dataset->pccd_refcount, 1);
-       dataset->pccd_hsmtool_type = HSMTOOL_POSIX;
 
        rc = pcc_dataset_rule_init(&dataset->pccd_rule, cmd);
        if (rc) {
@@ -1372,17 +1381,27 @@ void pcc_inode_free(struct inode *inode)
  * (fid->f_oid >> 16 & oxFFFF)/FID
  */
 #define MAX_PCC_DATABASE_PATH (6 * 5 + FID_NOBRACE_LEN + 1)
-static int pcc_fid2dataset_path(char *buf, int sz, struct lu_fid *fid)
-{
-       return snprintf(buf, sz, "%04x/%04x/%04x/%04x/%04x/%04x/"
-                       DFID_NOBRACE,
-                       (fid)->f_oid       & 0xFFFF,
-                       (fid)->f_oid >> 16 & 0xFFFF,
-                       (unsigned int)((fid)->f_seq       & 0xFFFF),
-                       (unsigned int)((fid)->f_seq >> 16 & 0xFFFF),
-                       (unsigned int)((fid)->f_seq >> 32 & 0xFFFF),
-                       (unsigned int)((fid)->f_seq >> 48 & 0xFFFF),
-                       PFID(fid));
+static int pcc_fid2dataset_path(struct pcc_dataset *dataset, char *buf,
+                               int sz, struct lu_fid *fid)
+{
+       switch (dataset->pccd_hsmtool_type) {
+       case HSMTOOL_POSIX_V1:
+               return snprintf(buf, sz, "%04x/%04x/%04x/%04x/%04x/%04x/"
+                               DFID_NOBRACE,
+                               (fid)->f_oid       & 0xFFFF,
+                               (fid)->f_oid >> 16 & 0xFFFF,
+                               (unsigned int)((fid)->f_seq       & 0xFFFF),
+                               (unsigned int)((fid)->f_seq >> 16 & 0xFFFF),
+                               (unsigned int)((fid)->f_seq >> 32 & 0xFFFF),
+                               (unsigned int)((fid)->f_seq >> 48 & 0xFFFF),
+                               PFID(fid));
+       case HSMTOOL_POSIX_V2:
+               return snprintf(buf, sz, "%04x/"DFID_NOBRACE,
+                               (__u32)((fid)->f_oid ^ (fid)->f_seq) & 0XFFFF,
+                               PFID(fid));
+       default:
+               return -EINVAL;
+       }
 }
 
 static inline const struct cred *pcc_super_cred(struct super_block *sb)
@@ -1459,16 +1478,26 @@ static int pcc_get_layout_info(struct inode *inode, struct cl_layout *clt)
 static int pcc_fid2dataset_fullpath(char *buf, int sz, struct lu_fid *fid,
                                    struct pcc_dataset *dataset)
 {
-       return snprintf(buf, sz, "%s/%04x/%04x/%04x/%04x/%04x/%04x/"
-                       DFID_NOBRACE,
-                       dataset->pccd_pathname,
-                       (fid)->f_oid       & 0xFFFF,
-                       (fid)->f_oid >> 16 & 0xFFFF,
-                       (unsigned int)((fid)->f_seq       & 0xFFFF),
-                       (unsigned int)((fid)->f_seq >> 16 & 0xFFFF),
-                       (unsigned int)((fid)->f_seq >> 32 & 0xFFFF),
-                       (unsigned int)((fid)->f_seq >> 48 & 0xFFFF),
-                       PFID(fid));
+       switch (dataset->pccd_hsmtool_type) {
+       case HSMTOOL_POSIX_V1:
+               return snprintf(buf, sz, "%s/%04x/%04x/%04x/%04x/%04x/%04x/"
+                               DFID_NOBRACE,
+                               dataset->pccd_pathname,
+                               (fid)->f_oid       & 0xFFFF,
+                               (fid)->f_oid >> 16 & 0xFFFF,
+                               (unsigned int)((fid)->f_seq       & 0xFFFF),
+                               (unsigned int)((fid)->f_seq >> 16 & 0xFFFF),
+                               (unsigned int)((fid)->f_seq >> 32 & 0xFFFF),
+                               (unsigned int)((fid)->f_seq >> 48 & 0xFFFF),
+                               PFID(fid));
+       case HSMTOOL_POSIX_V2:
+               return snprintf(buf, sz, "%s/%04x/"DFID_NOBRACE,
+                               dataset->pccd_pathname,
+                               (__u32)((fid)->f_oid ^ (fid)->f_seq) & 0XFFFF,
+                               PFID(fid));
+       default:
+               return -EINVAL;
+       }
 }
 
 /* Must be called with pcci->pcci_lock held */
@@ -3107,7 +3136,7 @@ static int __pcc_inode_create(struct pcc_dataset *dataset,
        if (path == NULL)
                return -ENOMEM;
 
-       pcc_fid2dataset_path(path, MAX_PCC_DATABASE_PATH, fid);
+       pcc_fid2dataset_path(dataset, path, MAX_PCC_DATABASE_PATH, fid);
 
        base = pcc_mkdir_p(dataset->pccd_path.dentry, path, 0);
        if (IS_ERR(base)) {
index acb8d25..33f0707 100644 (file)
@@ -252,6 +252,7 @@ struct pcc_cmd {
                        struct list_head         pccc_conds;
                        char                    *pccc_conds_str;
                        enum pcc_dataset_flags   pccc_flags;
+                       enum hsmtool_type        pccc_hsmtool_type;
                } pccc_add;
                struct pcc_cmd_del {
                        __u32                    pccc_pad;
index 3f04256..b01dd7f 100644 (file)
@@ -17,7 +17,7 @@ ALWAYS_EXCEPT+=""
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
 ENABLE_PROJECT_QUOTAS=${ENABLE_PROJECT_QUOTAS:-true}
-HSMTOOL_ARCHIVE_FORMAT=v1
+HSMTOOL_ARCHIVE_FORMAT=v2
 
 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
 
index 62b1b40..54c0345 100644 (file)
@@ -99,12 +99,8 @@ int hsm_scan_handle_dir(struct hsm_scan_control *hsc, struct list_head *head,
                    strcmp(ent->d_name, "shadow") == 0) {
                        llapi_printf(LLAPI_MSG_DEBUG,
                                     "skipping check of 'shadow' directory.\n");
-               } else if (depth < 6) {
-                       /* No regular file under this directory level */
+               } else {
                        if (ent->d_type == DT_REG) {
-                               llapi_printf(LLAPI_MSG_DEBUG,
-                                            "improved HSM layout for '%s' under directory '%s'?\n",
-                                            ent->d_name, pathname);
                                ret = hsc->hsc_func(pathname, ent->d_name, hsc);
                                if (ret && !rc) {
                                        hsc->hsc_errnum++;
@@ -128,26 +124,6 @@ int hsm_scan_handle_dir(struct hsm_scan_control *hsc, struct list_head *head,
                                rc = hsm_scan_item_alloc(head, fullname,
                                                         depth + 1);
                        }
-               } else if (depth == 6) {
-                       /* This is the directory level that should has files */
-                       if (ent->d_type == DT_DIR) {
-                               llapi_err_noerrno(LLAPI_MSG_DEBUG,
-                                                 "ignore too deep subdir '%s' under directory '%s'\n",
-                                                 ent->d_name, pathname);
-                               hsc->hsc_errnum++;
-                       } else if (ent->d_type == DT_REG) {
-                               ret = hsc->hsc_func(pathname, ent->d_name, hsc);
-                               if (ret && !rc) {
-                                       hsc->hsc_errnum++;
-                                       rc = ret;
-                                       /* ignore error, continue to check */
-                               }
-                       }
-               } else {
-                       hsc->hsc_errnum++;
-                       ret = -EINVAL;
-                       llapi_error(LLAPI_MSG_ERROR, ret,
-                                   "ignore too deep directory '%s'", pathname);
                }
        }
 
@@ -167,7 +143,8 @@ int hsm_scan_process(struct hsm_scan_control *hsc)
        int ret = 0;
        int rc;
 
-       if (hsc->hsc_type != HSMTOOL_POSIX)
+       if (hsc->hsc_type != HSMTOOL_POSIX_V1 &&
+           hsc->hsc_type != HSMTOOL_POSIX_V2)
                return -EOPNOTSUPP;
 
        rc = stat(hsc->hsc_hsmpath, &st);