Whamcloud - gitweb
LU-1581 utils: label methods
authorAlex Zhuravlev <bzzz@whamcloud.com>
Mon, 30 Jul 2012 14:01:54 +0000 (18:01 +0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 16 Aug 2012 19:18:21 +0000 (15:18 -0400)
label methods for ldiskfs and zfs, used by mount utility
to update the label upon the first successful mount.

Signed-off-by: Alex Zhuravlev <bzzz@whamcloud.com>
Change-Id: Ibd5e14bd10e39d71264d15bbee42021b089091ea
Reviewed-on: http://review.whamcloud.com/3611
Tested-by: Hudson
Reviewed-by: Jinshan Xiong <jinshan.xiong@whamcloud.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/utils/mount_lustre.c
lustre/utils/mount_utils.c
lustre/utils/mount_utils.h
lustre/utils/mount_utils_ldiskfs.c
lustre/utils/mount_utils_zfs.c

index 263f5d2..4364ea4 100644 (file)
@@ -670,6 +670,11 @@ int main(int argc, char *const argv[])
        } else if (!mop.mo_nomtab) {
                rc = update_mtab_entry(mop.mo_usource, mop.mo_target, "lustre",
                                       mop.mo_orig_options, 0,0,0);
        } else if (!mop.mo_nomtab) {
                rc = update_mtab_entry(mop.mo_usource, mop.mo_target, "lustre",
                                       mop.mo_orig_options, 0,0,0);
+
+               /* change label from <fsname>:<index> to <fsname>-<index>
+                * to indicate the device has been registered. */
+               if (mop.mo_ldd.ldd_flags & LDD_F_VIRGIN)
+                       (void) osd_label_lustre(&mop);
         }
 
        free(options);
         }
 
        free(options);
index 08e4b40..839c7f6 100644 (file)
@@ -534,6 +534,32 @@ int osd_tune_lustre(char *dev, struct mount_opts *mop)
        return ret;
 }
 
        return ret;
 }
 
+int osd_label_lustre(struct mount_opts *mop)
+{
+       struct lustre_disk_data *ldd = &mop->mo_ldd;
+       int ret;
+
+       switch (ldd->ldd_mount_type) {
+       case LDD_MT_LDISKFS:
+       case LDD_MT_LDISKFS2:
+               ret = ldiskfs_label_lustre(mop);
+               break;
+#ifdef HAVE_ZFS_OSD
+       case LDD_MT_ZFS:
+               ret = zfs_label_lustre(mop);
+               break;
+#endif /* HAVE_ZFS_OSD */
+       default:
+               fatal();
+               fprintf(stderr, "unknown fs type %d '%s'\n",
+                       ldd->ldd_mount_type, MT_STR(ldd));
+               ret = EINVAL;
+               break;
+       }
+
+       return ret;
+}
+
 int osd_init(void)
 {
        int ret = 0;
 int osd_init(void)
 {
        int ret = 0;
index acd0955..a698cb5 100644 (file)
@@ -123,6 +123,7 @@ int osd_prepare_lustre(struct mkfs_opts *mop,
                       char *default_mountopts, int default_len,
                       char *always_mountopts, int always_len);
 int osd_tune_lustre(char *dev, struct mount_opts *mop);
                       char *default_mountopts, int default_len,
                       char *always_mountopts, int always_len);
 int osd_tune_lustre(char *dev, struct mount_opts *mop);
+int osd_label_lustre(struct mount_opts *mop);
 int osd_init(void);
 void osd_fini(void);
 
 int osd_init(void);
 void osd_fini(void);
 
@@ -134,6 +135,7 @@ int ldiskfs_prepare_lustre(struct mkfs_opts *mop,
                           char *default_mountopts, int default_len,
                           char *always_mountopts, int always_len);
 int ldiskfs_tune_lustre(char *dev, struct mount_opts *mop);
                           char *default_mountopts, int default_len,
                           char *always_mountopts, int always_len);
 int ldiskfs_tune_lustre(char *dev, struct mount_opts *mop);
+int ldiskfs_label_lustre(struct mount_opts *mop);
 int ldiskfs_init(void);
 void ldiskfs_fini(void);
 
 int ldiskfs_init(void);
 void ldiskfs_fini(void);
 
@@ -146,6 +148,7 @@ int zfs_prepare_lustre(struct mkfs_opts *mop,
                       char *default_mountopts, int default_len,
                       char *always_mountopts, int always_len);
 int zfs_tune_lustre(char *dev, struct mount_opts *mop);
                       char *default_mountopts, int default_len,
                       char *always_mountopts, int always_len);
 int zfs_tune_lustre(char *dev, struct mount_opts *mop);
+int zfs_label_lustre(struct mount_opts *mop);
 int zfs_init(void);
 void zfs_fini(void);
 #endif
 int zfs_init(void);
 void zfs_fini(void);
 #endif
index a8419e9..f863ac9 100644 (file)
@@ -974,6 +974,18 @@ int ldiskfs_tune_lustre(char *dev, struct mount_opts *mop)
        return set_blockdev_tunables(dev, mop, 1);
 }
 
        return set_blockdev_tunables(dev, mop, 1);
 }
 
+int ldiskfs_label_lustre(struct mount_opts *mop)
+{
+       char label_cmd[PATH_MAX];
+       int rc;
+
+       snprintf(label_cmd, sizeof(label_cmd), E2LABEL" %s %s",
+                mop->mo_source, mop->mo_ldd.ldd_svname);
+       rc = run_command(label_cmd, sizeof(label_cmd));
+
+       return rc;
+}
+
 /* return canonicalized absolute pathname, even if the target file does not
  * exist, unlike realpath */
 static char *absolute_path(char *devname)
 /* return canonicalized absolute pathname, even if the target file does not
  * exist, unlike realpath */
 static char *absolute_path(char *devname)
index 8271135..88d7a0c 100644 (file)
@@ -624,6 +624,24 @@ int zfs_tune_lustre(char *dev, struct mount_opts *mop)
        return 0;
 }
 
        return 0;
 }
 
+int zfs_label_lustre(struct mount_opts *mop)
+{
+       zfs_handle_t *zhp;
+       int ret;
+
+       if (osd_check_zfs_setup() == 0)
+               return EINVAL;
+
+       zhp = zfs_open(g_zfs, mop->mo_source, ZFS_TYPE_FILESYSTEM);
+       if (zhp == NULL)
+               return EINVAL;
+
+       ret = zfs_set_prop_str(zhp, LDD_SVNAME_PROP, mop->mo_ldd.ldd_svname);
+       zfs_close(zhp);
+
+       return ret;
+}
+
 int zfs_init(void)
 {
        int ret = 0;
 int zfs_init(void)
 {
        int ret = 0;