From: Alex Zhuravlev Date: Mon, 30 Jul 2012 14:01:54 +0000 (+0400) Subject: LU-1581 utils: label methods X-Git-Tag: 2.2.93~1 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=cfef7958178b4e2981a44b1977da6577cc152ce4 LU-1581 utils: label methods label methods for ldiskfs and zfs, used by mount utility to update the label upon the first successful mount. Signed-off-by: Alex Zhuravlev Change-Id: Ibd5e14bd10e39d71264d15bbee42021b089091ea Reviewed-on: http://review.whamcloud.com/3611 Tested-by: Hudson Reviewed-by: Jinshan Xiong Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Brian Behlendorf Reviewed-by: Oleg Drokin --- diff --git a/lustre/utils/mount_lustre.c b/lustre/utils/mount_lustre.c index 263f5d2..4364ea4 100644 --- a/lustre/utils/mount_lustre.c +++ b/lustre/utils/mount_lustre.c @@ -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); + + /* change label from : to - + * to indicate the device has been registered. */ + if (mop.mo_ldd.ldd_flags & LDD_F_VIRGIN) + (void) osd_label_lustre(&mop); } free(options); diff --git a/lustre/utils/mount_utils.c b/lustre/utils/mount_utils.c index 08e4b40..839c7f6 100644 --- a/lustre/utils/mount_utils.c +++ b/lustre/utils/mount_utils.c @@ -534,6 +534,32 @@ int osd_tune_lustre(char *dev, struct mount_opts *mop) 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; diff --git a/lustre/utils/mount_utils.h b/lustre/utils/mount_utils.h index acd0955..a698cb5 100644 --- a/lustre/utils/mount_utils.h +++ b/lustre/utils/mount_utils.h @@ -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); +int osd_label_lustre(struct mount_opts *mop); 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); +int ldiskfs_label_lustre(struct mount_opts *mop); 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); +int zfs_label_lustre(struct mount_opts *mop); int zfs_init(void); void zfs_fini(void); #endif diff --git a/lustre/utils/mount_utils_ldiskfs.c b/lustre/utils/mount_utils_ldiskfs.c index a8419e9..f863ac9 100644 --- a/lustre/utils/mount_utils_ldiskfs.c +++ b/lustre/utils/mount_utils_ldiskfs.c @@ -974,6 +974,18 @@ int ldiskfs_tune_lustre(char *dev, struct mount_opts *mop) 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) diff --git a/lustre/utils/mount_utils_zfs.c b/lustre/utils/mount_utils_zfs.c index 8271135..88d7a0c 100644 --- a/lustre/utils/mount_utils_zfs.c +++ b/lustre/utils/mount_utils_zfs.c @@ -624,6 +624,24 @@ int zfs_tune_lustre(char *dev, struct mount_opts *mop) 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;