From 604c266a175b72500ef99793652b64ed4f842b2c Mon Sep 17 00:00:00 2001 From: James Simmons Date: Tue, 30 Apr 2019 09:42:10 -0400 Subject: [PATCH] LU-11803 obd: replace class_uuid with linux kernel version. We can replace the lustre custom class_uuid_t with the linux kernels uuid handling. Change-Id: I9a59b0b6027ccb95994a87f3a5dcdf80a8a56480 Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/33916 Reviewed-by: Petros Koutoupis Reviewed-by: Ben Evans Tested-by: Jenkins Reviewed-by: Yang Sheng Tested-by: Maloo Reviewed-by: Gu Zheng Reviewed-by: Oleg Drokin --- libcfs/autoconf/lustre-libcfs.m4 | 19 ++++++++++ libcfs/include/libcfs/linux/Makefile.am | 2 +- libcfs/include/libcfs/linux/linux-uuid.h | 64 ++++++++++++++++++++++++++++++++ lustre/include/lustre_scrub.h | 1 + lustre/include/obd_class.h | 12 ------ lustre/llite/llite_lib.c | 24 +++++++----- lustre/obdclass/obd_mount.c | 8 ++-- lustre/osd-ldiskfs/osd_scrub.c | 6 ++- lustre/osd-zfs/osd_scrub.c | 9 +++-- lustre/osp/lwp_dev.c | 7 ---- lustre/osp/osp_dev.c | 4 -- lustre/osp/osp_internal.h | 1 - 12 files changed, 113 insertions(+), 44 deletions(-) create mode 100644 libcfs/include/libcfs/linux/linux-uuid.h diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index 308316b..82a4ebc 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -888,6 +888,23 @@ rhashtable_lookup_get_insert_fast, [ ]) # LIBCFS_RHASHTABLE_LOOKUP_GET_INSERT_FAST # +# Kernel version 4.12-rc3 f9727a17db9bab71ddae91f74f11a8a2f9a0ece6 +# renamed uuid_be to uuid_t +# +AC_DEFUN([LIBCFS_UUID_T], [ +LB_CHECK_COMPILE([if 'uuid_t' exist], +uuid_t, [ + #include +],[ + uuid_t uuid; + + memset(uuid.b, 0, 16); +],[ + AC_DEFINE(HAVE_UUID_T, 1, ['uuid_t' exist]) +]) +]) # LIBCFS_UUID_T + +# # LIBCFS_WAIT_QUEUE_ENTRY # # Kernel version 4.13 ac6424b981bce1c4bc55675c6ce11bfe1bbfa64f @@ -1053,6 +1070,8 @@ LIBCFS_HOTPLUG_STATE_MACHINE # 4.11 LIBCFS_RHASHTABLE_LOOKUP_GET_INSERT_FAST LIBCFS_SCHED_HEADERS +# 4.12 +LIBCFS_UUID_T # 4.13 LIBCFS_WAIT_QUEUE_ENTRY # 4.14 diff --git a/libcfs/include/libcfs/linux/Makefile.am b/libcfs/include/libcfs/linux/Makefile.am index 031c849..0aaef36 100644 --- a/libcfs/include/libcfs/linux/Makefile.am +++ b/libcfs/include/libcfs/linux/Makefile.am @@ -1,2 +1,2 @@ EXTRA_DIST = linux-misc.h linux-fs.h linux-mem.h linux-time.h linux-cpu.h \ - linux-list.h linux-hash.h linux-crypto.h + linux-list.h linux-hash.h linux-uuid.h linux-crypto.h diff --git a/libcfs/include/libcfs/linux/linux-uuid.h b/libcfs/include/libcfs/linux/linux-uuid.h new file mode 100644 index 0000000..c6129f4 --- /dev/null +++ b/libcfs/include/libcfs/linux/linux-uuid.h @@ -0,0 +1,64 @@ +/* + * GPL HEADER START + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU General Public License + * version 2 along with this program; If not, see + * http://www.gnu.org/licenses/gpl-2.0.html + * + * GPL HEADER END + */ +/* + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. + * Use is subject to license terms. + * + * Copyright (c) 2011, 2017, Intel Corporation. + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. + */ + +#ifndef __LIBCFS_LINUX_UUID_H__ +#define __LIBCFS_LINUX_UUID_H__ + +#include + +#define UUID_SIZE 16 + +/* + * The original linux UUID code had uuid_be and uuid_le. + * Later uuid_le was changed to guid_t and uuid_be + * to uuid_t. See for details kernel commit: + * + * f9727a17db9bab71ddae91f74f11a8a2f9a0ece6 + */ +#ifndef HAVE_UUID_T +typedef struct { + __u8 b[UUID_SIZE]; +} uuid_t; + +static inline void uuid_copy(uuid_t *dst, uuid_t *src) +{ + memcpy(dst, src, sizeof(uuid_t)); +} + +static inline bool uuid_equal(const uuid_t *u1, const uuid_t *u2) +{ + return memcmp(u1, u2, sizeof(uuid_t)) == 0; +} + +#endif + +#endif /* __LIBCFS_LINUX_UUID_H__ */ diff --git a/lustre/include/lustre_scrub.h b/lustre/include/lustre_scrub.h index 3eba040..d03e7a4 100644 --- a/lustre/include/lustre_scrub.h +++ b/lustre/include/lustre_scrub.h @@ -33,6 +33,7 @@ #ifndef _LUSTRE_SCRUB_H # define _LUSTRE_SCRUB_H +#include #include #include diff --git a/lustre/include/obd_class.h b/lustre/include/obd_class.h index 18e1628..d0e4a0d 100644 --- a/lustre/include/obd_class.h +++ b/lustre/include/obd_class.h @@ -1802,15 +1802,6 @@ int lustre_register_fs(void); int lustre_unregister_fs(void); int lustre_check_exclusion(struct super_block *sb, char *svname); -typedef __u8 class_uuid_t[16]; -static inline void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out) -{ - snprintf(out->uuid, sizeof(out->uuid), "%02x%02x%02x%02x-%02x%02x-" - "%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", - uu[14], uu[15], uu[12], uu[13], uu[10], uu[11], uu[8], uu[9], - uu[6], uu[7], uu[4], uu[5], uu[2], uu[3], uu[0], uu[1]); -} - /* lustre_peer.c */ int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index); int class_add_uuid(const char *uuid, __u64 nid); @@ -1820,9 +1811,6 @@ int class_check_uuid(struct obd_uuid *uuid, __u64 nid); /* class_obd.c */ extern char obd_jobid_name[]; -/* prng.c */ -#define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t)) - /* statfs_pack.c */ struct kstatfs; void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs); diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index da0db39..2548dbd 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -37,9 +37,11 @@ #define DEBUG_SUBSYSTEM S_LLITE #include +#include #include #include #include +#include #include #include #include @@ -71,7 +73,6 @@ static struct ll_sb_info *ll_init_sbi(void) unsigned long pages; unsigned long lru_page_max; struct sysinfo si; - class_uuid_t uuid; int i; ENTRY; @@ -101,10 +102,6 @@ static struct ll_sb_info *ll_init_sbi(void) sbi->ll_ra_info.ra_max_pages = sbi->ll_ra_info.ra_max_pages_per_file; sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1; - ll_generate_random_uuid(uuid); - class_uuid_unparse(uuid, &sbi->ll_sb_uuid); - CDEBUG(D_CONFIG, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid); - sbi->ll_flags |= LL_SBI_VERBOSE; #ifdef ENABLE_CHECKSUM sbi->ll_flags |= LL_SBI_CHECKSUM; @@ -1031,6 +1028,7 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt) char name[MAX_STRING_SIZE]; int md_len = 0; int dt_len = 0; + uuid_t uuid; char *ptr; int len; int err; @@ -1055,14 +1053,16 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt) if (err) GOTO(out_free_cfg, err); - err = super_setup_bdi_name(sb, "lustre-%016lx", cfg_instance); - if (err) - GOTO(out_free_cfg, err); - #ifndef HAVE_DCACHE_LOCK /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */ sb->s_d_op = &ll_d_ops; #endif + /* UUID handling */ + generate_random_uuid(uuid.b); + snprintf(sbi->ll_sb_uuid.uuid, UUID_SIZE, "%pU", uuid.b); + + CDEBUG(D_CONFIG, "llite sb uuid: %s\n", sbi->ll_sb_uuid.uuid); + /* Get fsname */ len = strlen(profilenm); ptr = strrchr(profilenm, '-'); @@ -1083,9 +1083,13 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt) sbi->ll_fsname[len] = '\0'; /* Mount info */ - snprintf(name, MAX_STRING_SIZE, "%.*s-%016lx", len, + snprintf(name, sizeof(name), "%.*s-%016lx", len, profilenm, cfg_instance); + err = super_setup_bdi_name(sb, "%s", name); + if (err) + GOTO(out_free_cfg, err); + /* Call ll_debugfs_register_super() before lustre_process_log() * so that "llite.*.*" params can be processed correctly. */ diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index 53e3c8b..65fe8fa 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -43,6 +43,8 @@ #include #include +#include +#include #include #include #include @@ -222,7 +224,7 @@ int lustre_start_mgc(struct super_block *sb) struct obd_device *obd; struct obd_export *exp; struct obd_uuid *uuid = NULL; - class_uuid_t uuidc; + uuid_t uuidc; lnet_nid_t nid; char nidstr[LNET_NIDSTR_SIZE]; char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL; @@ -405,8 +407,8 @@ int lustre_start_mgc(struct super_block *sb) if (uuid == NULL) GOTO(out_free, rc = -ENOMEM); - ll_generate_random_uuid(uuidc); - class_uuid_unparse(uuidc, uuid); + generate_random_uuid(uuidc.b); + snprintf(uuid->uuid, UUID_SIZE, "%pU", uuidc.b); /* Start the MGC */ rc = lustre_start_simple(mgcname, LUSTRE_MGC_NAME, diff --git a/lustre/osd-ldiskfs/osd_scrub.c b/lustre/osd-ldiskfs/osd_scrub.c index efe89a4..8d405ba3 100644 --- a/lustre/osd-ldiskfs/osd_scrub.c +++ b/lustre/osd-ldiskfs/osd_scrub.c @@ -2669,8 +2669,10 @@ int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev) "failed to allocate RAM for report\n", osd_dev2name(dev)); } else { - class_uuid_unparse(sf->sf_uuid, old_uuid); - class_uuid_unparse(es->s_uuid, new_uuid); + 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); diff --git a/lustre/osd-zfs/osd_scrub.c b/lustre/osd-zfs/osd_scrub.c index d3c3e90..56a718b 100644 --- a/lustre/osd-zfs/osd_scrub.c +++ b/lustre/osd-zfs/osd_scrub.c @@ -1468,10 +1468,11 @@ int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev) "failed to allocate RAM for report\n", osd_name(dev)); } else { - class_uuid_unparse(sf->sf_uuid, old_uuid); - class_uuid_unparse(dev->od_uuid, new_uuid); - CDEBUG(D_LFSCK, "%s: UUID has been changed " - "from %s to %s\n", osd_name(dev), + 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); } scrub_file_reset(scrub, dev->od_uuid, SF_INCONSISTENT); diff --git a/lustre/osp/lwp_dev.c b/lustre/osp/lwp_dev.c index c240e25..f6277d3 100644 --- a/lustre/osp/lwp_dev.c +++ b/lustre/osp/lwp_dev.c @@ -49,7 +49,6 @@ struct lwp_device { struct lu_device lpd_dev; struct obd_device *lpd_obd; /* corresponding OBD device */ - struct obd_uuid lpd_cluuid;/* UUID of LWP */ struct obd_export *lpd_exp; /* export of LWP */ struct ptlrpc_thread lpd_notify_thread; /* notify thread */ int lpd_connects; /* use count, 0 or 1 */ @@ -83,7 +82,6 @@ static int lwp_setup(const struct lu_env *env, struct lwp_device *lwp, char *lwp_name = lwp->lpd_obd->obd_name; char *server_uuid = NULL; char *ptr; - class_uuid_t uuid; struct obd_import *imp; int len = strlen(lwp_name) + 1; int rc; @@ -128,11 +126,6 @@ static int lwp_setup(const struct lu_env *env, struct lwp_device *lwp, imp = lwp->lpd_obd->u.cli.cl_import; rc = ptlrpc_init_import(imp); - if (rc) - GOTO(out, rc); - - ll_generate_random_uuid(uuid); - class_uuid_unparse(uuid, &lwp->lpd_cluuid); out: if (bufs != NULL) OBD_FREE_PTR(bufs); diff --git a/lustre/osp/osp_dev.c b/lustre/osp/osp_dev.c index c8133f1..b6e88ce 100644 --- a/lustre/osp/osp_dev.c +++ b/lustre/osp/osp_dev.c @@ -1010,7 +1010,6 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp, { struct obd_device *obd; struct obd_import *imp; - class_uuid_t uuid; char *src, *tgt, *mdt, *osdname = NULL; int rc; long idx; @@ -1202,9 +1201,6 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp, /* * Initiate connect to OST */ - ll_generate_random_uuid(uuid); - class_uuid_unparse(uuid, &osp->opd_cluuid); - imp = obd->u.cli.cl_import; rc = ptlrpc_init_import(imp); diff --git a/lustre/osp/osp_internal.h b/lustre/osp/osp_internal.h index 64ef6e3..f9b474a 100644 --- a/lustre/osp/osp_internal.h +++ b/lustre/osp/osp_internal.h @@ -177,7 +177,6 @@ struct osp_device { struct osp_rpc_lock opd_rpc_lock; struct obd_device *opd_obd; struct obd_export *opd_exp; - struct obd_uuid opd_cluuid; struct obd_connect_data *opd_connect_data; int opd_connects; /* connection status. */ -- 1.8.3.1