Whamcloud - gitweb
LU-11838 scrub: handle s_uuid change to uuid_t 89/34689/8
authorJames Simmons <jsimmons@infradead.org>
Thu, 20 Jun 2019 20:57:01 +0000 (16:57 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 27 Jun 2019 21:33:29 +0000 (21:33 +0000)
The 4.12 kernel changed the s_uuid field in struct super_block from
an character array to an uuid_t. While ldiskfs uses it own s_uuid
field in struct ext4_super_block that field is a char array instead
of an uuid. Currently on going effort are being down in the linux
kernel to move to uuid_t so I suspect this will change in the future.
Since this is the case change all the character arrays for uuid
handling to uuid_t located in the scrubbing code. Change osd-ldiskfs
to use the struct super_block uuid, which is equivalent to s_es
version, to handle the uuid_t changes now.

Change-Id: I40643d342b5bc17a6ef922e99b3e8524930822de
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/34689
Tested-by: Jenkins
Reviewed-by: Shaun Tancheff <stancheff@cray.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/autoconf/lustre-core.m4
lustre/include/lustre_scrub.h
lustre/obdclass/scrub.c
lustre/osd-ldiskfs/osd_internal.h
lustre/osd-ldiskfs/osd_oi.c
lustre/osd-ldiskfs/osd_scrub.c
lustre/osd-zfs/osd_internal.h
lustre/osd-zfs/osd_scrub.c

index 5e82b61..a0538b3 100644 (file)
@@ -3040,6 +3040,23 @@ current_time, [
 ]) # LIBCFS_CURRENT_TIME
 
 #
+# Kernel version 4.12-rc3 85787090a21eb749d8b347eaf9ff1a455637473c
+# changed struct super_block s_uuid into a proper uuid_t
+#
+AC_DEFUN([LC_SUPER_BLOCK_S_UUID], [
+LB_CHECK_COMPILE([if 'struct super_block' s_uuid is uuid_t],
+super_block_s_uuid, [
+       #include <linux/fs.h>
+],[
+       struct super_block sb;
+
+       uuid_parse(NULL, &sb.s_uuid);
+],[
+       AC_DEFINE(HAVE_S_UUID_AS_UUID_T, 1, ['s_uuid' is an uuid_t])
+])
+]) # LC_SUPER_BLOCK_S_UUID
+
+#
 # LC_SUPER_SETUP_BDI_NAME
 #
 # Kernel version 4.12 commit 9594caf216dc0fe3e318b34af0127276db661241
@@ -3418,6 +3435,7 @@ AC_DEFUN([LC_PROG_LINUX], [
 
        # 4.12
        LC_CURRENT_TIME
+       LC_SUPER_BLOCK_S_UUID
        LC_SUPER_SETUP_BDI_NAME
        LC_BI_STATUS
 
index d03e7a4..38d4fb5 100644 (file)
@@ -186,7 +186,7 @@ enum auto_scrub {
 
 struct scrub_file {
        /* 128-bit uuid for volume. */
-       __u8    sf_uuid[16];
+       uuid_t  sf_uuid;
 
        /* See 'enum scrub_flags'. */
        __u64   sf_flags;
@@ -335,8 +335,8 @@ struct lustre_index_restore_unit {
        char                    liru_name[0];
 };
 
-void scrub_file_init(struct lustre_scrub *scrub, __u8 *uuid);
-void scrub_file_reset(struct lustre_scrub *scrub, __u8 *uuid, __u64 flags);
+void scrub_file_init(struct lustre_scrub *scrub, uuid_t uuid);
+void scrub_file_reset(struct lustre_scrub *scrub, uuid_t uuid, u64 flags);
 int scrub_file_load(const struct lu_env *env, struct lustre_scrub *scrub);
 int scrub_file_store(const struct lu_env *env, struct lustre_scrub *scrub);
 int scrub_checkpoint(const struct lu_env *env, struct lustre_scrub *scrub);
index b2e93c6..c828bb6 100644 (file)
@@ -46,7 +46,7 @@ static inline struct dt_device *scrub_obj2dev(struct dt_object *obj)
 
 static void scrub_file_to_cpu(struct scrub_file *des, struct scrub_file *src)
 {
-       memcpy(des->sf_uuid, src->sf_uuid, 16);
+       uuid_copy(&des->sf_uuid, &src->sf_uuid);
        des->sf_flags   = le64_to_cpu(src->sf_flags);
        des->sf_magic   = le32_to_cpu(src->sf_magic);
        des->sf_status  = le16_to_cpu(src->sf_status);
@@ -80,7 +80,7 @@ static void scrub_file_to_cpu(struct scrub_file *des, struct scrub_file *src)
 
 static void scrub_file_to_le(struct scrub_file *des, struct scrub_file *src)
 {
-       memcpy(des->sf_uuid, src->sf_uuid, 16);
+       uuid_copy(&des->sf_uuid, &src->sf_uuid);
        des->sf_flags   = cpu_to_le64(src->sf_flags);
        des->sf_magic   = cpu_to_le32(src->sf_magic);
        des->sf_status  = cpu_to_le16(src->sf_status);
@@ -112,18 +112,18 @@ static void scrub_file_to_le(struct scrub_file *des, struct scrub_file *src)
        memcpy(des->sf_oi_bitmap, src->sf_oi_bitmap, SCRUB_OI_BITMAP_SIZE);
 }
 
-void scrub_file_init(struct lustre_scrub *scrub, __u8 *uuid)
+void scrub_file_init(struct lustre_scrub *scrub, uuid_t uuid)
 {
        struct scrub_file *sf = &scrub->os_file;
 
        memset(sf, 0, sizeof(*sf));
-       memcpy(sf->sf_uuid, uuid, 16);
+       uuid_copy(&sf->sf_uuid, &uuid);
        sf->sf_magic = SCRUB_MAGIC_V1;
        sf->sf_status = SS_INIT;
 }
 EXPORT_SYMBOL(scrub_file_init);
 
-void scrub_file_reset(struct lustre_scrub *scrub, __u8 *uuid, __u64 flags)
+void scrub_file_reset(struct lustre_scrub *scrub, uuid_t uuid, u64 flags)
 {
        struct scrub_file *sf = &scrub->os_file;
 
@@ -131,7 +131,7 @@ void scrub_file_reset(struct lustre_scrub *scrub, __u8 *uuid, __u64 flags)
               "%#llx, add flags = %#llx\n",
               scrub->os_name, sf->sf_flags, flags);
 
-       memcpy(sf->sf_uuid, uuid, 16);
+       uuid_copy(&sf->sf_uuid, &uuid);
        sf->sf_status = SS_INIT;
        sf->sf_flags |= flags;
        sf->sf_flags &= ~SF_AUTO;
index 24d9e91..db2c3c7 100644 (file)
@@ -301,6 +301,7 @@ struct osd_device {
        /* service name associated with the osd device */
        char                      od_svname[MAX_OBD_NAME];
        char                      od_mntdev[MAX_OBD_NAME];
+       uuid_t                  od_uuid;
 
        /* quota slave instance for inode */
        struct qsd_instance      *od_quota_slave_md;
index 9d17ad8..cd7e696 100644 (file)
@@ -432,8 +432,7 @@ int osd_oi_init(struct osd_thread_info *info, struct osd_device *osd,
                        sf->sf_oi_count = osd_oi_count;
                }
 
-               scrub_file_reset(scrub, LDISKFS_SB(osd_sb(osd))->s_es->s_uuid,
-                                SF_RECREATED);
+               scrub_file_reset(scrub, osd->od_uuid, SF_RECREATED);
                count = sf->sf_oi_count;
                goto create;
        }
@@ -454,9 +453,7 @@ int osd_oi_init(struct osd_thread_info *info, struct osd_device *osd,
                         *      and restored after former upgrading from 1.8
                         *      to 2.x. Fortunately, the osd_fid_lookup()can
                         *      verify the inode to decrease the risk. */
-                       scrub_file_reset(scrub,
-                                        LDISKFS_SB(osd_sb(osd))->s_es->s_uuid,
-                                        SF_UPGRADE);
+                       scrub_file_reset(scrub, osd->od_uuid, SF_UPGRADE);
                GOTO(out, rc = 1);
        } else if (rc != -ENOENT) {
                CERROR("%s: can't open %s: rc = %d\n",
@@ -471,8 +468,7 @@ int osd_oi_init(struct osd_thread_info *info, struct osd_device *osd,
                memset(sf->sf_oi_bitmap, 0, SCRUB_OI_BITMAP_SIZE);
                for (i = 0; i < count; i++)
                        ldiskfs_set_bit(i, sf->sf_oi_bitmap);
-               scrub_file_reset(scrub, LDISKFS_SB(osd_sb(osd))->s_es->s_uuid,
-                                SF_RECREATED);
+               scrub_file_reset(scrub, osd->od_uuid, SF_RECREATED);
        } else {
                count = sf->sf_oi_count = osd_oi_count;
        }
index 8d405ba..2d5c558 100644 (file)
@@ -472,8 +472,7 @@ static int osd_scrub_prep(const struct lu_env *env, struct osd_device *dev)
        }
 
        if (flags & SS_RESET)
-               scrub_file_reset(scrub,
-                       LDISKFS_SB(osd_sb(dev))->s_es->s_uuid, 0);
+               scrub_file_reset(scrub, dev->od_uuid, 0);
 
        if (flags & SS_AUTO_FULL) {
                scrub->os_full_speed = 1;
@@ -989,8 +988,8 @@ static void osd_scrub_join(const struct lu_env *env, struct osd_device *dev,
                sf->sf_param &= ~SP_DRYRUN;
 
        if (flags & SS_RESET) {
-               scrub_file_reset(scrub, LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
-                       inconsistent ? SF_INCONSISTENT : 0);
+               scrub_file_reset(scrub, dev->od_uuid,
+                                inconsistent ? SF_INCONSISTENT : 0);
                sf->sf_status = SS_SCANNING;
        }
 
@@ -1997,8 +1996,7 @@ osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
                RETURN(0);
 
        if (!(sf->sf_flags & SF_INCONSISTENT)) {
-               scrub_file_reset(scrub, LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
-                                SF_INCONSISTENT);
+               scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
                rc = scrub_file_store(info->oti_env, scrub);
                if (rc != 0)
                        RETURN(rc);
@@ -2338,9 +2336,8 @@ osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
                if (rc == -ENOENT) {
                        /* It is 1.8 MDT device. */
                        if (!(sf->sf_flags & SF_UPGRADE)) {
-                               scrub_file_reset(scrub,
-                                       LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
-                                       SF_UPGRADE);
+                               scrub_file_reset(scrub, dev->od_uuid,
+                                                SF_UPGRADE);
                                sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
                                rc = scrub_file_store(info->oti_env, scrub);
                        } else {
@@ -2582,7 +2579,6 @@ int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev)
        struct lvfs_run_ctxt *ctxt = &dev->od_scrub.os_ctxt;
        struct scrub_file *sf = &scrub->os_file;
        struct super_block *sb = osd_sb(dev);
-       struct ldiskfs_super_block *es = LDISKFS_SB(sb)->s_es;
        struct lvfs_run_ctxt saved;
        struct file *filp;
        struct inode *inode;
@@ -2636,10 +2632,15 @@ int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev)
        if (IS_ERR_OR_NULL(obj))
                RETURN(obj ? PTR_ERR(obj) : -ENOENT);
 
+#ifndef HAVE_S_UUID_AS_UUID_T
+       memcpy(dev->od_uuid.b, sb->s_uuid, UUID_SIZE);
+#else
+       uuid_copy(&dev->od_uuid, &sb->s_uuid);
+#endif
        scrub->os_obj = obj;
        rc = scrub_file_load(env, scrub);
        if (rc == -ENOENT || rc == -EFAULT) {
-               scrub_file_init(scrub, es->s_uuid);
+               scrub_file_init(scrub, dev->od_uuid);
                /* If the "/O" dir does not exist when mount (indicated by
                 * osd_device::od_maybe_new), neither for the "/OI_scrub",
                 * then it is quite probably that the device is a new one,
@@ -2658,32 +2659,13 @@ int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev)
        } else if (rc < 0) {
                GOTO(cleanup_obj, rc);
        } else {
-               if (memcmp(sf->sf_uuid, es->s_uuid, 16) != 0) {
-                       struct obd_uuid *old_uuid;
-                       struct obd_uuid *new_uuid;
-
-                       OBD_ALLOC_PTR(old_uuid);
-                       OBD_ALLOC_PTR(new_uuid);
-                       if (old_uuid == NULL || new_uuid == NULL) {
-                               CERROR("%s: UUID has been changed, but"
-                                      "failed to allocate RAM for report\n",
-                                      osd_dev2name(dev));
-                       } else {
-                               snprintf(old_uuid->uuid, UUID_SIZE, "%pU",
-                                        sf->sf_uuid);
-                               snprintf(new_uuid->uuid, UUID_SIZE, "%pU",
-                                        es->s_uuid);
-                               CDEBUG(D_LFSCK, "%s: UUID has been changed "
-                                      "from %s to %s\n", osd_dev2name(dev),
-                                      old_uuid->uuid, new_uuid->uuid);
-                       }
-                       scrub_file_reset(scrub, es->s_uuid, SF_INCONSISTENT);
+               if (!uuid_equal(&sf->sf_uuid, &dev->od_uuid)) {
+                       CDEBUG(D_LFSCK,
+                              "%s: UUID has been changed from %pU to %pU\n",
+                              osd_dev2name(dev), &sf->sf_uuid, &dev->od_uuid);
+                       scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
                        dirty = true;
                        restored = true;
-                       if (old_uuid != NULL)
-                               OBD_FREE_PTR(old_uuid);
-                       if (new_uuid != NULL)
-                               OBD_FREE_PTR(new_uuid);
                } else if (sf->sf_status == SS_SCANNING) {
                        sf->sf_status = SS_CRASHED;
                        dirty = true;
index d71004e..d88ef63 100644 (file)
@@ -351,7 +351,7 @@ struct osd_device {
        enum lustre_index_backup_policy od_index_backup_policy;
        char                     od_mntdev[128];
        char                     od_svname[128];
-       char                     od_uuid[16];
+       uuid_t                   od_uuid;
 
        int                      od_connects;
        int                      od_index;
index 56a718b..8758ebd 100644 (file)
@@ -1417,7 +1417,7 @@ int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev)
        bool dirty = false;
        ENTRY;
 
-       memcpy(dev->od_uuid,
+       memcpy(dev->od_uuid.b,
               &dsl_dataset_phys(dev->od_os->os_dsl_dataset)->ds_guid,
               sizeof(dsl_dataset_phys(dev->od_os->os_dsl_dataset)->ds_guid));
        memset(&dev->od_scrub, 0, sizeof(struct lustre_scrub));
@@ -1457,30 +1457,12 @@ int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev)
        } else if (rc < 0) {
                GOTO(cleanup_obj, rc);
        } else {
-               if (memcmp(sf->sf_uuid, dev->od_uuid, 16) != 0) {
-                       struct obd_uuid *old_uuid;
-                       struct obd_uuid *new_uuid;
-
-                       OBD_ALLOC_PTR(old_uuid);
-                       OBD_ALLOC_PTR(new_uuid);
-                       if (!old_uuid || !new_uuid) {
-                               CERROR("%s: UUID has been changed, but"
-                                      "failed to allocate RAM for report\n",
-                                      osd_name(dev));
-                       } else {
-                               snprintf(old_uuid->uuid, UUID_SIZE, "%pU", sf->sf_uuid);
-                               snprintf(new_uuid->uuid, UUID_SIZE, "%pU", dev->od_uuid);
-                               CDEBUG(D_LFSCK,
-                                      "%s: UUID has been changed from %s to %s\n",
-                                      osd_name(dev),
-                                      old_uuid->uuid, new_uuid->uuid);
-                       }
+               if (!uuid_equal(&sf->sf_uuid, &dev->od_uuid)) {
+                       CDEBUG(D_LFSCK,
+                              "%s: UUID has been changed from %pU to %pU\n",
+                              osd_name(dev), &sf->sf_uuid, &dev->od_uuid);
                        scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT);
                        dirty = true;
-                       if (old_uuid)
-                               OBD_FREE_PTR(old_uuid);
-                       if (new_uuid)
-                               OBD_FREE_PTR(new_uuid);
                } else if (sf->sf_status == SS_SCANNING) {
                        sf->sf_status = SS_CRASHED;
                        dirty = true;