Whamcloud - gitweb
LU-8837 utils: make tools lightweight for lustre clients 15/28315/11
authorJames Simmons <uja.ornl@yahoo.com>
Thu, 9 Nov 2017 00:50:48 +0000 (19:50 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 22 Nov 2017 03:55:12 +0000 (03:55 +0000)
Currently the lustre tools are built for the server target even
for the case of clients rpms. Rework the tools so server specific
code is not built for the client only case. The UAPI headers
lustre_log_user.h, lustre_barrier_user.h, and lustre_disk.h are
server specific and are not available in the upstream client.
So make our tools not to depend on those headers in the client
case. With this change it is simple step to make our tools
buildable against upstream. Last move user land specific code
from lustre_disk.h to mount_utils.h. Don't install server UAPI
headers on client targets.

Change-Id: I6b2b780ac0e7338a085ee6a8747097f0097efca1
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/28315
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Tested-by: Jenkins
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/include/uapi/linux/lustre/Makefile.am
lustre/include/uapi/linux/lustre/lustre_disk.h
lustre/mdt/mdt_internal.h
lustre/utils/Makefile.am
lustre/utils/lctl.c
lustre/utils/mount_lustre.c
lustre/utils/mount_utils.c
lustre/utils/mount_utils.h
lustre/utils/obd.c
lustre/utils/obdctl.h
lustre/utils/wiretest.c

index a2e099e..cd941ec 100644 (file)
 
 lustreincludedir = /usr/include/linux/lustre
 lustreinclude_HEADERS = \
-       lustre_barrier_user.h \
        lustre_cfg.h \
-       lustre_disk.h \
        lustre_fid.h \
        lustre_fiemap.h \
        lustre_idl.h \
        lustre_ioctl.h \
        lustre_kernelcomm.h \
-       lustre_lfsck_user.h \
-       lustre_log_user.h \
        lustre_ostid.h \
        lustre_param.h \
        lustre_user.h \
        lustre_ver.h
 
+if SERVER
+lustreinclude_HEADERS += \
+       lustre_barrier_user.h \
+       lustre_disk.h \
+       lustre_lfsck_user.h \
+       lustre_log_user.h
+endif
+
 EXTRA_DIST = \
        lustre_barrier_user.h \
        lustre_cfg.h \
index 8887c82..6a0b145 100644 (file)
@@ -114,36 +114,9 @@ enum ldd_mount_type {
        LDD_MT_LAST
 };
 
-/* On-disk configuration file. In host-endian order. */
-struct lustre_disk_data {
-       __u32 ldd_magic;
-       __u32 ldd_feature_compat;       /* compatible feature flags */
-       __u32 ldd_feature_rocompat;     /* read-only compatible feature flags */
-       __u32 ldd_feature_incompat;     /* incompatible feature flags */
-
-       __u32 ldd_config_ver;           /* config rewrite count - not used */
-       __u32 ldd_flags;                /* LDD_SV_TYPE */
-       __u32 ldd_svindex;              /* server index (0001), must match
-                                        * svname
-                                        */
-       __u32 ldd_mount_type;           /* target fs type LDD_MT_* */
-       char  ldd_fsname[64];           /* filesystem this server is part of,
-                                        * MTI_NAME_MAXLEN
-                                        */
-       char  ldd_svname[64];           /* this server's name (lustre-mdt0001)*/
-       __u8  ldd_uuid[40];             /* server UUID (COMPAT_146) */
-
-       char  ldd_userdata[1024 - 200]; /* arbitrary user string '200' */
-       __u8  ldd_padding[4096 - 1024]; /* 1024 */
-       char  ldd_mount_opts[4096];     /* target fs mount opts '4096' */
-       char  ldd_params[4096];         /* key=value pairs '8192' */
-};
-
 /****************** last_rcvd file *********************/
 
 #define LR_EXPIRE_INTERVALS 16 /**< number of intervals to track transno */
-#define ENOENT_VERSION 1       /** 'virtual' version of non-existent object */
-
 #define LR_SERVER_SIZE 512
 #define LR_CLIENT_START        8192
 #define LR_CLIENT_SIZE 128
index 2a9d21c..eed78f8 100644 (file)
@@ -264,6 +264,8 @@ struct mdt_device {
 #define MDT_SERVICE_WATCHDOG_FACTOR    (2)
 #define MDT_COS_DEFAULT         (0)
 
+#define ENOENT_VERSION 1       /** 'virtual' version of non-existent object */
+
 struct mdt_object {
        struct lu_object_header mot_header;
        struct lu_object        mot_obj;
index e4e64a3..0eee6e0 100644 (file)
@@ -51,7 +51,10 @@ endif
 noinst_LIBRARIES = liblustreapitmp.a
 endif # UTILS
 
-lctl_SOURCES = lustre_lfsck.c portals.c debug.c obd.c lustre_cfg.c lctl.c obdctl.h lsnapshot.c
+lctl_SOURCES = portals.c debug.c obd.c lustre_cfg.c lctl.c obdctl.h
+if SERVER
+lctl_SOURCES += lustre_lfsck.c lsnapshot.c
+endif
 lctl_LDADD :=  liblustreapi.a $(LIBCFS) $(LIBREADLINE) $(PTHREAD_LIBS)
 lctl_DEPENDENCIES := $(LIBCFS) liblustreapi.a
 
index 6764100..abd869e 100644 (file)
@@ -245,6 +245,7 @@ command_t cmdlist[] = {
         "list pools and pools members\n"
         "usage: pool_list  <fsname>[.<poolname>] | <pathname>"},
 
+#ifdef HAVE_SERVER_SUPPORT
        /* Barrier commands */
        {"===  Barrier ==", NULL, 0, "barrier management"},
        {"barrier_freeze", jt_barrier_freeze, 0,
@@ -297,7 +298,7 @@ command_t cmdlist[] = {
         "usage: snapshot_umount <-F | --fsname fsname> [-h | --help]\n"
         "                       <-n | --name ssname>\n"
         "                       [-r | --rsh remote_shell]"},
-
+#endif /* HAVE_SERVER_SUPPORT */
        /* Nodemap commands */
        {"=== Nodemap ===", NULL, 0, "nodemap management"},
        {"nodemap_activate", jt_nodemap_activate, 0,
@@ -451,7 +452,7 @@ command_t cmdlist[] = {
         "get the version of an object on servers\n"
         "usage: getobjversion <fid>\n"
         "       getobjversion -i <id> -g <group>"},
-
+#ifdef HAVE_SERVER_SUPPORT
        /* LFSCK commands */
        {"==== LFSCK ====", NULL, 0, "LFSCK"},
        {"lfsck_start", jt_lfsck_start, 0, "start LFSCK\n"
@@ -471,7 +472,7 @@ command_t cmdlist[] = {
         "usage: lfsck_query [-M | --device MDT_device] [-h | --help]\n"
         "                   [-t | --type lfsck_type[,lfsck_type...]]\n"
         "                   [-w | --wait]"},
-
+#endif /* HAVE_SERVER_SUPPORT */
        {"==== obsolete (DANGEROUS) ====", NULL, 0, "obsolete (DANGEROUS)"},
        /* some test scripts still use these */
        {"cfg_device", jt_obd_device, 0,
index de3833f..74d41b3 100644 (file)
@@ -347,6 +347,7 @@ out_options:
        return rc;
 }
 
+#ifdef HAVE_SERVER_SUPPORT
 /* Add mgsnids from ldd params */
 static int add_mgsnids(struct mount_opts *mop, char *options,
                       const char *params, size_t options_len)
@@ -580,6 +581,7 @@ static int parse_ldd(char *source, struct mount_opts *mop,
 
        return rc;
 }
+#endif /* HAVE_SERVER_SUPPORT */
 
 static void set_defaults(struct mount_opts *mop)
 {
@@ -701,6 +703,7 @@ static int parse_opts(int argc, char *const argv[], struct mount_opts *mop)
        return 0;
 }
 
+#ifdef HAVE_SERVER_SUPPORT
 /* change label from <fsname>:<index> to
  * <fsname>-<index> to indicate the device has
  * been registered. only if the label is
@@ -729,6 +732,7 @@ static void label_lustre(struct mount_opts *mop)
                }
        }
 }
+#endif /* HAVE_SERVER_SUPPORT */
 
 int main(int argc, char *const argv[])
 {
@@ -818,6 +822,7 @@ int main(int argc, char *const argv[])
 
        client = (strstr(mop.mo_usource, ":/") != NULL);
        if (!client) {
+#ifdef HAVE_SERVER_SUPPORT
                rc = osd_init();
                if (rc)
                        goto out_options;
@@ -825,6 +830,10 @@ int main(int argc, char *const argv[])
                rc = parse_ldd(mop.mo_source, &mop, options, maxopt_len);
                if (rc)
                        goto out_osd;
+#else
+               rc = -EINVAL;
+               goto out_options;
+#endif
        }
 
        /* In Linux 2.4, the target device doesn't get passed to any of our
@@ -837,13 +846,14 @@ int main(int argc, char *const argv[])
                printf("mounting device %s at %s, flags=%#x options=%s\n",
                       mop.mo_source, mop.mo_target, flags, options);
 
+#ifdef HAVE_SERVER_SUPPORT
        if (!client && osd_tune_lustre(mop.mo_source, &mop)) {
                if (verbose)
                        fprintf(stderr, "%s: unable to set tunables for %s"
                                        " (may cause reduced IO performance)\n",
                                        argv[0], mop.mo_source);
        }
-
+#endif
 #ifdef HAVE_GSS
        if (mop.mo_skpath[0] != '\0') {
                /* Treat shared key failures as fatal */
@@ -864,10 +874,7 @@ int main(int argc, char *const argv[])
                for (i = 0, rc = -EAGAIN; i <= mop.mo_retry && rc != 0; i++) {
                        rc = mount(mop.mo_source, mop.mo_target, "lustre",
                                   flags, (void *)options);
-                       if (rc == 0) {
-                               if (!client)
-                                       label_lustre(&mop);
-                       } else {
+                       if (rc != 0) {
                                 if (verbose) {
                                         fprintf(stderr, "%s: mount %s at %s "
                                                 "failed: %s retries left: "
@@ -884,6 +891,11 @@ int main(int argc, char *const argv[])
                                } else {
                                        rc = errno;
                                }
+#ifdef HAVE_SERVER_SUPPORT
+                       } else {
+                               if (!client)
+                                       label_lustre(&mop);
+#endif
                        }
                }
        }
@@ -965,9 +977,10 @@ int main(int argc, char *const argv[])
        }
 
 out_osd:
+#ifdef HAVE_SERVER_SUPPORT
        if (!client)
                osd_fini();
-
+#endif
 out_options:
        free(options);
 
index e3f44d0..82543df 100644 (file)
@@ -68,7 +68,9 @@ extern int verbose;
 #define vprint(fmt, arg...) if (verbose > 0) printf(fmt, ##arg)
 #define verrprint(fmt, arg...) if (verbose >= 0) fprintf(stderr, fmt, ##arg)
 
+#ifdef HAVE_SERVER_SUPPORT
 static struct module_backfs_ops *backfs_ops[LDD_MT_LAST];
+#endif
 
 void fatal(void)
 {
@@ -117,6 +119,7 @@ int run_command(char *cmd, int cmdsz)
         return rc;
 }
 
+#ifdef HAVE_SERVER_SUPPORT
 int add_param(char *buf, char *key, char *val)
 {
        int end = sizeof(((struct lustre_disk_data *)0)->ldd_params);
@@ -193,6 +196,7 @@ int append_param(char *buf, char *key, char *val, char sep)
 
        return add_param(buf, key, str);
 }
+#endif
 
 char *strscat(char *dst, char *src, int buflen)
 {
@@ -395,6 +399,7 @@ void trim_mountfsoptions(char *s)
                *p-- = '\0';
 }
 
+#ifdef HAVE_SERVER_SUPPORT
 /* Setup a file in the first unused loop_device */
 int loop_setup(struct mkfs_opts *mop)
 {
@@ -895,6 +900,7 @@ __u64 get_device_size(char* device)
        /* return value in KB */
        return size >> 10;
 }
+#endif
 
 int file_create(char *path, __u64 size)
 {
@@ -941,7 +947,7 @@ int file_create(char *path, __u64 size)
        return 0;
 }
 
-
+#ifdef HAVE_SERVER_SUPPORT
 struct lustre_cfg_entry {
        struct list_head lce_list;
        char             lce_name[0];
@@ -1130,6 +1136,7 @@ out:
 
        return ret;
 }
+#endif /* HAVE_SERVER_SUPPORT */
 
 #ifdef HAVE_GSS
 #ifdef HAVE_OPENSSL_SSK
index a8cff6d..744d106 100644 (file)
 #include <sys/stat.h>
 
 #include <libcfs/util/list.h>
-#include <linux/lustre/lustre_disk.h>
 #include <linux/lustre/lustre_param.h>
+#ifdef HAVE_SERVER_SUPPORT
+#include <linux/lustre/lustre_disk.h>
+#endif
 
 extern char *progname;
 extern int verbose;
@@ -81,6 +83,32 @@ extern int failover;
 /* Maximum length of on-disk parameters in the form key=<value> */
 #define PARAM_MAX              4096
 
+#ifdef HAVE_SERVER_SUPPORT
+/* On-disk configuration file. In host-endian order. */
+struct lustre_disk_data {
+       __u32 ldd_magic;
+       __u32 ldd_feature_compat;       /* compatible feature flags */
+       __u32 ldd_feature_rocompat;     /* read-only compatible feature flags */
+       __u32 ldd_feature_incompat;     /* incompatible feature flags */
+
+       __u32 ldd_config_ver;           /* config rewrite count - not used */
+       __u32 ldd_flags;                /* LDD_SV_TYPE */
+       __u32 ldd_svindex;              /* server index (0001), must match
+                                        * svname
+                                        */
+       __u32 ldd_mount_type;           /* target fs type LDD_MT_* */
+       char  ldd_fsname[64];           /* filesystem this server is part of,
+                                        * MTI_NAME_MAXLEN
+                                        */
+       char  ldd_svname[64];           /* this server's name (lustre-mdt0001)*/
+       __u8  ldd_uuid[40];             /* server UUID (COMPAT_146) */
+
+       char  ldd_userdata[1024 - 200]; /* arbitrary user string '200' */
+       __u8  ldd_padding[4096 - 1024]; /* 1024 */
+       char  ldd_mount_opts[4096];     /* target fs mount opts '4096' */
+       char  ldd_params[4096];         /* key=value pairs '8192' */
+};
+
 /* used to describe the options to format the lustre disk, not persistent */
 struct mkfs_opts {
        struct lustre_disk_data mo_ldd; /* to be written in MOUNT_DATA_FILE */
@@ -94,10 +122,13 @@ struct mkfs_opts {
        int     mo_flags;
        int     mo_mgs_failnodes;
 };
+#endif
 
 /* used to describe the options to mount the lustre disk */
 struct mount_opts {
+#ifdef HAVE_SERVER_SUPPORT
        struct lustre_disk_data  mo_ldd;
+#endif
        char    *mo_orig_options;
        char    *mo_usource;            /* user-specified mount device */
        char    *mo_source;             /* our mount device name */
@@ -115,6 +146,7 @@ struct mount_opts {
        int      mo_max_sectors_kb;
 };
 
+#ifdef HAVE_SERVER_SUPPORT
 int get_mountdata(char *, struct lustre_disk_data *);
 
 static inline char *mt_str(enum ldd_mount_type mt)
@@ -142,6 +174,7 @@ static inline char *mt_type(enum ldd_mount_type mt)
        };
        return mount_type_string[mt];
 }
+#endif /* HAVE_SERVER_SUPPORT */
 
 #define MT_STR(data)   mt_str((data)->ldd_mount_type)
 
@@ -168,6 +201,7 @@ int update_mtab_entry(char *spec, char *mtpt, char *type, char *opts,
 int update_utab_entry(struct mount_opts *mop);
 int check_mountfsoptions(char *mountopts, char *wanted_mountopts);
 void trim_mountfsoptions(char *s);
+#ifdef HAVE_SERVER_SUPPORT
 __u64 get_device_size(char* device);
 int lustre_rename_fsname(struct mkfs_opts *mop, const char *mntpt,
                         const char *oldname);
@@ -220,6 +254,8 @@ struct module_backfs_ops ldiskfs_ops;
 
 struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type);
 void unload_backfs_ops(struct module_backfs_ops *ops);
+#endif
+
 #ifdef HAVE_OPENSSL_SSK
 int load_shared_keys(struct mount_opts *mop);
 #else
index 0cc3361..90aa7cb 100644 (file)
@@ -4073,6 +4073,7 @@ out:
         return rc;
 }
 
+#ifdef HAVE_SERVER_SUPPORT
 static const char *barrier_status2name(enum barrier_status status)
 {
        switch (status) {
@@ -4344,6 +4345,7 @@ int jt_barrier_rescan(int argc, char **argv)
 
        return rc;
 }
+#endif /* HAVE_SERVER_SUPPORT */
 
 int jt_get_obj_version(int argc, char **argv)
 {
index 41823b2..3d71bdd 100644 (file)
@@ -33,7 +33,9 @@
 #ifndef _OBDCTL_H_
 #define _OBDCTL_H_
 
+#ifdef HAVE_SERVER_SUPPORT
 #include <linux/lustre/lustre_barrier_user.h>
+#endif
 
 /* ptlctl.a */
 int ptl_initialize(int argc, char **argv);
@@ -163,6 +165,7 @@ int jt_lcfg_setparam(int argc, char **argv);
 int jt_lcfg_listparam(int argc, char **argv);
 
 int jt_pool_cmd(int argc, char **argv);
+#ifdef HAVE_SERVER_SUPPORT
 int jt_barrier_freeze(int argc, char **argv);
 int jt_barrier_thaw(int argc, char **argv);
 int __jt_barrier_stat(const char *fsname, struct barrier_ctl *bc);
@@ -174,6 +177,7 @@ int jt_snapshot_modify(int argc, char **argv);
 int jt_snapshot_list(int argc, char **argv);
 int jt_snapshot_mount(int argc, char **argv);
 int jt_snapshot_umount(int argc, char **argv);
+#endif /* HAVE_SERVER_SUPPORT */
 int jt_nodemap_activate(int argc, char **argv);
 int jt_nodemap_add(int argc, char **argv);
 int jt_nodemap_del(int argc, char **argv);
@@ -189,9 +193,11 @@ int jt_nodemap_info(int argc, char **argv);
 int jt_changelog_register(int argc, char **argv);
 int jt_changelog_deregister(int argc, char **argv);
 
+#ifdef HAVE_SERVER_SUPPORT
 /* lustre_lfsck.c */
 int jt_lfsck_start(int argc, char **argv);
 int jt_lfsck_stop(int argc, char **argv);
 int jt_lfsck_query(int argc, char **argv);
+#endif /* HAVE_SERVER_SUPPORT */
 
 #endif
index f62a0b0..11ea015 100644 (file)
 #include <string.h>
 
 #include <linux/lustre/lustre_idl.h>
+#ifdef HAVE_SERVER_SUPPORT
 #include <linux/lustre/lustre_lfsck_user.h>
 #include <linux/lustre/lustre_disk.h>
+#endif
 
 #define LASSERT(cond) if (!(cond)) { printf("failed " #cond "\n"); ret = 1; }
 #define LASSERTF(cond, fmt, ...) if (!(cond)) { printf("failed '" #cond "'" fmt, ## __VA_ARGS__);ret = 1;}
@@ -5182,12 +5184,14 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)offsetof(struct lfsck_request, lr_padding_3));
        LASSERTF((int)sizeof(((struct lfsck_request *)0)->lr_padding_3) == 8, "found %lld\n",
                 (long long)(int)sizeof(((struct lfsck_request *)0)->lr_padding_3));
+#ifdef HAVE_SERVER_SUPPORT
        LASSERTF(LFSCK_TYPE_SCRUB == 0x00000000UL, "found 0x%.8xUL\n",
                (unsigned)LFSCK_TYPE_SCRUB);
        LASSERTF(LFSCK_TYPE_LAYOUT == 0x00000001UL, "found 0x%.8xUL\n",
                (unsigned)LFSCK_TYPE_LAYOUT);
        LASSERTF(LFSCK_TYPE_NAMESPACE == 0x00000004UL, "found 0x%.8xUL\n",
                (unsigned)LFSCK_TYPE_NAMESPACE);
+#endif
        LASSERTF(LE_LASTID_REBUILDING == 1, "found %lld\n",
                 (long long)LE_LASTID_REBUILDING);
        LASSERTF(LE_LASTID_REBUILT == 2, "found %lld\n",