4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
35 #endif /* HAVE_CONFIG_H */
45 #include <lustre_disk.h>
46 #include <lustre_ver.h>
47 #include <sys/mount.h>
49 #include <sys/utsname.h>
50 #include <linux/loop.h>
51 #include <sys/types.h>
54 #include <lustre/lustre_idl.h>
55 #include <lustre_cfg.h>
57 #include <sys/types.h>
58 #include <sys/xattr.h>
62 #include <lustre/utils/gss/sk_utils.h>
65 #include "mount_utils.h"
67 extern char *progname;
70 #define vprint(fmt, arg...) if (verbose > 0) printf(fmt, ##arg)
71 #define verrprint(fmt, arg...) if (verbose >= 0) fprintf(stderr, fmt, ##arg)
73 static struct module_backfs_ops *backfs_ops[LDD_MT_LAST];
78 fprintf(stderr, "\n%s FATAL: ", progname);
81 int run_command(char *cmd, int cmdsz)
83 char log[] = "/tmp/run_command_logXXXXXX";
86 if ((cmdsz - strlen(cmd)) < 6) {
88 fprintf(stderr, "Command buffer overflow: %.*s...\n",
94 printf("cmd: %s\n", cmd);
96 if ((fd = mkstemp(log)) >= 0) {
102 strcat(cmd, " 2>&1");
104 /* Can't use popen because we need the rv of the command */
106 if (rc && (fd >= 0)) {
109 fp = fopen(log, "r");
111 while (fgets(buf, sizeof(buf), fp) != NULL) {
122 int add_param(char *buf, char *key, char *val)
124 int end = sizeof(((struct lustre_disk_data *)0)->ldd_params);
125 int start = strlen(buf);
129 keylen = strlen(key);
130 if (start + 1 + keylen + strlen(val) >= end) {
131 fprintf(stderr, "%s: params are too long-\n%s %s%s\n",
132 progname, buf, key ? key : "", val);
136 sprintf(buf + start, " %s%s", key ? key : "", val);
140 int get_param(char *buf, char *key, char **val)
142 int i, key_len = strlen(key);
145 ptr = strstr(buf, key);
147 *val = strdup(ptr + key_len);
151 for (i = 0; i < strlen(*val); i++)
152 if (((*val)[i] == ' ') || ((*val)[i] == '\0'))
162 int append_param(char *buf, char *key, char *val, char sep)
164 int key_len, i, offset, old_val_len;
165 char *ptr = NULL, str[1024];
168 ptr = strstr(buf, key);
170 /* key doesn't exist yet, so just add it */
172 return add_param(buf, key, val);
174 key_len = strlen(key);
176 /* Copy previous values to str */
177 for (i = 0; i < sizeof(str); ++i) {
178 if ((ptr[i+key_len] == ' ') || (ptr[i+key_len] == '\0'))
180 str[i] = ptr[i+key_len];
182 if (i == sizeof(str))
186 offset = old_val_len+key_len;
188 /* Move rest of buf to overwrite previous key and value */
189 for (i = 0; ptr[i+offset] != '\0'; ++i)
190 ptr[i] = ptr[i+offset];
194 snprintf(str+old_val_len, sizeof(str)-old_val_len, "%c%s", sep, val);
196 return add_param(buf, key, str);
199 char *strscat(char *dst, char *src, int buflen)
202 if (strlen(dst) + strlen(src) >= buflen) {
203 fprintf(stderr, "string buffer overflow (max %d): '%s' + '%s'"
204 "\n", buflen, dst, src);
207 return strcat(dst, src);
210 char *strscpy(char *dst, char *src, int buflen)
213 return strscat(dst, src, buflen);
216 int check_mtab_entry(char *spec1, char *spec2, char *mtpt, char *type)
221 fp = setmntent(MOUNTED, "r");
225 while ((mnt = getmntent(fp)) != NULL) {
226 if ((strcmp(mnt->mnt_fsname, spec1) == 0 ||
227 strcmp(mnt->mnt_fsname, spec2) == 0) &&
228 (mtpt == NULL || strcmp(mnt->mnt_dir, mtpt) == 0) &&
229 (type == NULL || strcmp(mnt->mnt_type, type) == 0)) {
240 #include <linux/magic.h>
242 static int mtab_is_proc(const char *mtab)
245 if (statfs(mtab, &s) < 0)
248 return (s.f_type == PROC_SUPER_MAGIC);
253 # include <libmount/libmount.h>
256 * The libmount is part of util-linux since 2.18.
257 * We use it to update utab to avoid umount would
258 * blocked in some rare case.
260 int update_utab_entry(struct mount_opts *mop)
262 struct libmnt_fs *fs = mnt_new_fs();
263 struct libmnt_update *upd;
266 mnt_fs_set_source(fs, mop->mo_source);
267 mnt_fs_set_target(fs, mop->mo_target);
268 mnt_fs_set_fstype(fs, "lustre");
269 mnt_fs_set_attributes(fs, "lustre");
271 upd = mnt_new_update();
275 rc = mnt_update_set_fs(upd, mop->mo_nomtab ? MS_REMOUNT : 0, NULL, fs);
276 if (rc == 1) /* update is unnecessary */
280 "error: failed to save utab entry: rc = %d\n", rc);
282 rc = mnt_update_table(upd, NULL);
285 mnt_free_update(upd);
291 int update_utab_entry(struct mount_opts *mop)
295 #endif /* HAVE_LIBMOUNT */
297 int update_mtab_entry(char *spec, char *mtpt, char *type, char *opts,
298 int flags, int freq, int pass)
304 /* Don't update mtab if it is linked to any file in /proc direcotry.*/
305 if (mtab_is_proc(MOUNTED))
308 mnt.mnt_fsname = spec;
311 mnt.mnt_opts = opts ? opts : "";
313 mnt.mnt_passno = pass;
315 fp = setmntent(MOUNTED, "a+");
317 fprintf(stderr, "%s: setmntent(%s): %s\n",
318 progname, MOUNTED, strerror (errno));
321 if ((addmntent(fp, &mnt)) == 1) {
322 fprintf(stderr, "%s: addmntent: %s\n",
323 progname, strerror (errno));
332 /* Search for opt in mntlist, returning true if found.
334 static int in_mntlist(char *opt, char *mntlist)
336 char *ml, *mlp, *item, *ctx = NULL;
338 if (!(ml = strdup(mntlist))) {
339 fprintf(stderr, "%s: out of memory\n", progname);
343 while ((item = strtok_r(mlp, ",", &ctx))) {
344 if (!strcmp(opt, item))
349 return (item != NULL);
352 /* Issue a message on stderr for every item in wanted_mountopts that is not
353 * present in mountopts. The justwarn boolean toggles between error and
354 * warning message. Return an error count.
356 int check_mountfsoptions(char *mountopts, char *wanted_mountopts)
358 char *ml, *mlp, *item, *ctx = NULL;
361 if (!(ml = strdup(wanted_mountopts))) {
362 fprintf(stderr, "%s: out of memory\n", progname);
366 while ((item = strtok_r(mlp, ",", &ctx))) {
367 if (!in_mntlist(item, mountopts)) {
368 fprintf(stderr, "%s: Error: mandatory mount option"
369 " '%s' is missing\n", progname, item);
378 /* Trim embedded white space, leading and trailing commas from string s.
380 void trim_mountfsoptions(char *s)
386 memmove(p, p + 1, strlen(p + 1) + 1);
393 memmove(&s[0], &s[1], strlen(&s[1]) + 1);
395 p = s + strlen(s) - 1;
396 while (p >= s && *p == ',')
400 /* Setup a file in the first unused loop_device */
401 int loop_setup(struct mkfs_opts *mop)
407 /* Figure out the loop device names */
408 if (!access("/dev/loop0", F_OK | R_OK) ||
409 !access("/dev/loop-control", F_OK | R_OK)) {
410 strcpy(loop_base, "/dev/loop\0");
411 } else if (!access("/dev/loop/0", F_OK | R_OK)) {
412 strcpy(loop_base, "/dev/loop/\0");
414 fprintf(stderr, "%s: can't access loop devices\n", progname);
418 /* Find unused loop device */
419 for (i = 0; i < MAX_LOOP_DEVICES; i++) {
421 int cmdsz = sizeof(cmd);
423 #ifdef HAVE_LOOP_CTL_GET_FREE
424 ret = open("/dev/loop-control", O_RDWR);
426 fprintf(stderr, "%s: can't access loop control\n", progname);
429 /* find or allocate a free loop device to use */
430 i = ioctl(ret, LOOP_CTL_GET_FREE);
433 fprintf(stderr, "%s: access loop control error\n", progname);
436 sprintf(l_device, "%s%d", loop_base, i);
438 sprintf(l_device, "%s%d", loop_base, i);
439 if (access(l_device, F_OK | R_OK))
442 snprintf(cmd, cmdsz, "losetup %s > /dev/null 2>&1", l_device);
445 /* losetup gets 1 (ret=256) for non-set-up device */
447 /* Set up a loopback device to our file */
448 snprintf(cmd, cmdsz, "losetup %s %s", l_device,
450 ret = run_command(cmd, cmdsz);
452 /* someone else picked up this loop device
456 fprintf(stderr, "%s: error %d on losetup: %s\n",
458 ret >= 0 ? strerror(ret) : "");
461 strscpy(mop->mo_loopdev, l_device,
462 sizeof(mop->mo_loopdev));
467 fprintf(stderr, "%s: out of loop devices!\n", progname);
471 int loop_cleanup(struct mkfs_opts *mop)
476 if ((mop->mo_flags & MO_IS_LOOP) && *mop->mo_loopdev) {
479 sprintf(cmd, "losetup -d %s", mop->mo_loopdev);
480 for (tries = 0; tries < 3; tries++) {
481 ret = run_command(cmd, sizeof(cmd));
489 fprintf(stderr, "cannot cleanup %s: rc = %d\n",
490 mop->mo_loopdev, ret);
494 int loop_format(struct mkfs_opts *mop)
498 if (mop->mo_device_kb == 0) {
500 fprintf(stderr, "loop device requires a --device-size= "
505 fd = creat(mop->mo_device, S_IRUSR|S_IWUSR);
508 fprintf(stderr, "%s: Unable to create backing store: %s\n",
509 progname, strerror(errno));
513 if (ftruncate(fd, mop->mo_device_kb * 1024) != 0) {
516 fprintf(stderr, "%s: Unable to truncate backing store: %s\n",
517 progname, strerror(errno));
525 #define DLSYM(prefix, sym, func) \
528 snprintf(_fname, sizeof(_fname), "%s_%s", prefix, #func); \
529 sym->func = (typeof(sym->func))dlsym(sym->dl_handle, _fname); \
533 * Load plugin for a given mount_type from ${pkglibdir}/mount_osd_FSTYPE.so and
534 * return struct of function pointers (will be freed in unloack_backfs_module).
536 * \param[in] mount_type Mount type to load module for.
537 * \retval Value of backfs_ops struct
538 * \retval NULL if no module exists
540 struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type)
543 char *error, filename[512], fsname[512], *name;
544 struct module_backfs_ops *ops;
546 /* This deals with duplicate ldd_mount_types resolving to same OSD layer
547 * plugin (e.g. ext3/ldiskfs/ldiskfs2 all being ldiskfs) */
548 strncpy(fsname, mt_type(mount_type), sizeof(fsname));
549 name = fsname + sizeof("osd-") - 1;
551 /* change osd- to osd_ */
552 fsname[sizeof("osd-") - 2] = '_';
554 snprintf(filename, sizeof(filename), PLUGIN_DIR"/mount_%s.so", fsname);
556 handle = dlopen(filename, RTLD_LAZY);
558 /* Check for $LUSTRE environment variable from test-framework.
559 * This allows using locally built modules to be used.
561 if (handle == NULL) {
563 dirname = getenv("LUSTRE");
565 snprintf(filename, sizeof(filename),
566 "%s/utils/.libs/mount_%s.so",
568 handle = dlopen(filename, RTLD_LAZY);
572 /* Do not clutter up console with missing types */
576 ops = malloc(sizeof(*ops));
582 ops->dl_handle = handle;
583 dlerror(); /* Clear any existing error */
585 DLSYM(name, ops, init);
586 DLSYM(name, ops, fini);
587 DLSYM(name, ops, read_ldd);
588 DLSYM(name, ops, write_ldd);
589 DLSYM(name, ops, erase_ldd);
590 DLSYM(name, ops, print_ldd_params);
591 DLSYM(name, ops, is_lustre);
592 DLSYM(name, ops, make_lustre);
593 DLSYM(name, ops, prepare_lustre);
594 DLSYM(name, ops, tune_lustre);
595 DLSYM(name, ops, label_lustre);
596 DLSYM(name, ops, rename_fsname);
597 DLSYM(name, ops, enable_quota);
602 fprintf(stderr, "%s\n", error);
608 /* optional methods */
609 DLSYM(name, ops, fix_mountopts);
615 * Unload plugin and free backfs_ops structure. Must be called the same number
616 * of times as load_backfs_module is.
618 void unload_backfs_module(struct module_backfs_ops *ops)
623 dlclose(ops->dl_handle);
627 /* Return true if backfs_ops has operations for the given mount_type. */
628 int backfs_mount_type_okay(enum ldd_mount_type mount_type)
630 if (mount_type >= LDD_MT_LAST || mount_type < 0) {
632 fprintf(stderr, "fs type out of range %d\n", mount_type);
635 if (backfs_ops[mount_type] == NULL) {
637 fprintf(stderr, "unhandled/unloaded fs type %d '%s'\n",
638 mount_type, mt_str(mount_type));
644 /* Write the server config files */
645 int osd_write_ldd(struct mkfs_opts *mop)
647 struct lustre_disk_data *ldd = &mop->mo_ldd;
650 if (backfs_mount_type_okay(ldd->ldd_mount_type))
651 ret = backfs_ops[ldd->ldd_mount_type]->write_ldd(mop);
658 /* Read the server config files */
659 int osd_read_ldd(char *dev, struct lustre_disk_data *ldd)
663 if (backfs_mount_type_okay(ldd->ldd_mount_type))
664 ret = backfs_ops[ldd->ldd_mount_type]->read_ldd(dev, ldd);
671 /* Erase param from the server config files */
672 int osd_erase_ldd(struct mkfs_opts *mop, char *param)
674 struct lustre_disk_data *ldd = &mop->mo_ldd;
677 if (backfs_mount_type_okay(ldd->ldd_mount_type))
678 ret = backfs_ops[ldd->ldd_mount_type]->erase_ldd(mop, param);
685 /* Print ldd_params */
686 void osd_print_ldd_params(struct mkfs_opts *mop)
688 struct lustre_disk_data *ldd = &mop->mo_ldd;
690 if (backfs_mount_type_okay(ldd->ldd_mount_type))
691 backfs_ops[ldd->ldd_mount_type]->print_ldd_params(mop);
694 /* Was this device formatted for Lustre */
695 int osd_is_lustre(char *dev, unsigned *mount_type)
699 vprint("checking for existing Lustre data: ");
701 for (i = 0; i < LDD_MT_LAST; ++i) {
702 if (backfs_ops[i] != NULL &&
703 backfs_ops[i]->is_lustre(dev, mount_type)) {
709 vprint("not found\n");
713 /* Build fs according to type */
714 int osd_make_lustre(struct mkfs_opts *mop)
716 struct lustre_disk_data *ldd = &mop->mo_ldd;
719 if (backfs_mount_type_okay(ldd->ldd_mount_type))
720 ret = backfs_ops[ldd->ldd_mount_type]->make_lustre(mop);
727 int osd_prepare_lustre(struct mkfs_opts *mop,
728 char *wanted_mountopts, size_t len)
730 struct lustre_disk_data *ldd = &mop->mo_ldd;
733 if (backfs_mount_type_okay(ldd->ldd_mount_type))
734 ret = backfs_ops[ldd->ldd_mount_type]->prepare_lustre(mop,
735 wanted_mountopts, len);
742 int osd_fix_mountopts(struct mkfs_opts *mop, char *mountopts, size_t len)
744 struct lustre_disk_data *ldd = &mop->mo_ldd;
746 if (!backfs_mount_type_okay(ldd->ldd_mount_type))
749 if (backfs_ops[ldd->ldd_mount_type]->fix_mountopts == NULL)
752 return backfs_ops[ldd->ldd_mount_type]->fix_mountopts(mop, mountopts,
756 int osd_tune_lustre(char *dev, struct mount_opts *mop)
758 struct lustre_disk_data *ldd = &mop->mo_ldd;
761 if (backfs_mount_type_okay(ldd->ldd_mount_type))
762 ret = backfs_ops[ldd->ldd_mount_type]->tune_lustre(dev, mop);
769 int osd_label_lustre(struct mount_opts *mop)
771 struct lustre_disk_data *ldd = &mop->mo_ldd;
774 if (backfs_mount_type_okay(ldd->ldd_mount_type))
775 ret = backfs_ops[ldd->ldd_mount_type]->label_lustre(mop);
782 /* Rename filesystem fsname */
783 int osd_rename_fsname(struct mkfs_opts *mop, const char *oldname)
785 struct lustre_disk_data *ldd = &mop->mo_ldd;
788 if (backfs_mount_type_okay(ldd->ldd_mount_type))
789 ret = backfs_ops[ldd->ldd_mount_type]->rename_fsname(mop,
797 /* Enable quota accounting */
798 int osd_enable_quota(struct mkfs_opts *mop)
800 struct lustre_disk_data *ldd = &mop->mo_ldd;
803 if (backfs_mount_type_okay(ldd->ldd_mount_type))
804 ret = backfs_ops[ldd->ldd_mount_type]->enable_quota(mop);
813 int i, rc, ret = EINVAL;
815 for (i = 0; i < LDD_MT_LAST; ++i) {
817 backfs_ops[i] = load_backfs_module(i);
818 if (backfs_ops[i] != NULL)
819 rc = backfs_ops[i]->init();
821 backfs_ops[i]->fini();
822 unload_backfs_module(backfs_ops[i]);
823 backfs_ops[i] = NULL;
835 for (i = 0; i < LDD_MT_LAST; ++i) {
836 if (backfs_ops[i] != NULL) {
837 backfs_ops[i]->fini();
838 unload_backfs_module(backfs_ops[i]);
839 backfs_ops[i] = NULL;
844 __u64 get_device_size(char* device)
849 fd = open(device, O_RDONLY);
851 fprintf(stderr, "%s: cannot open %s: %s\n",
852 progname, device, strerror(errno));
857 /* size in bytes. bz5831 */
858 ret = ioctl(fd, BLKGETSIZE64, (void*)&size);
863 ret = ioctl(fd, BLKGETSIZE, (void*)&lsize);
864 size = (__u64)lsize * 512;
869 fprintf(stderr, "%s: size ioctl failed: %s\n",
870 progname, strerror(errno));
874 vprint("device size = %juMB\n", (uintmax_t)(size >> 20));
875 /* return value in KB */
879 int file_create(char *path, __u64 size)
886 * Since "size" is in KB, the file offset it represents could overflow
889 size_max = (off_t)1 << (_FILE_OFFSET_BITS - 1 - 10);
890 if (size >= size_max) {
891 fprintf(stderr, "%s: %ju KB: Backing store size must be "
892 "smaller than %ju KB\n", progname, (uintmax_t) size,
893 (uintmax_t)size_max);
897 ret = access(path, F_OK);
904 fd = creat(path, S_IRUSR|S_IWUSR);
907 fprintf(stderr, "%s: Unable to create backing store: %s\n",
908 progname, strerror(errno));
912 ret = ftruncate(fd, size * 1024);
916 fprintf(stderr, "%s: Unable to truncate backing store: %s\n",
917 progname, strerror(errno));
925 struct lustre_cfg_entry {
926 struct list_head lce_list;
930 static struct lustre_cfg_entry *lustre_cfg_entry_init(const char *name)
932 struct lustre_cfg_entry *lce;
933 int len = strlen(name) + 1;
935 lce = malloc(sizeof(*lce) + len);
937 INIT_LIST_HEAD(&lce->lce_list);
938 memcpy(lce->lce_name, name, len);
944 static void lustre_cfg_entry_fini(struct lustre_cfg_entry *lce)
949 int lustre_rename_fsname(struct mkfs_opts *mop, const char *mntpt,
952 struct lustre_disk_data *ldd = &mop->mo_ldd;
953 struct lr_server_data lsd;
957 struct dirent64 *dirent;
958 struct lustre_cfg_entry *lce;
959 struct list_head cfg_list;
960 int old_namelen = strlen(oldname);
961 int new_namelen = strlen(ldd->ldd_fsname);
965 INIT_LIST_HEAD(&cfg_list);
967 snprintf(filepnm, sizeof(filepnm), "%s/%s", mntpt, LAST_RCVD);
968 fd = open(filepnm, O_RDWR);
977 fprintf(stderr, "Unable to open %s: %s\n",
978 filepnm, strerror(ret));
982 ret = read(fd, &lsd, sizeof(lsd));
983 if (ret != sizeof(lsd)) {
986 fprintf(stderr, "Unable to read %s: %s\n",
987 filepnm, strerror(ret));
992 ret = lseek(fd, 0, SEEK_SET);
996 fprintf(stderr, "Unable to lseek %s: %s\n",
997 filepnm, strerror(ret));
1002 /* replace fsname in lr_server_data::lsd_uuid. */
1003 if (old_namelen > new_namelen)
1004 memmove(lsd.lsd_uuid + new_namelen,
1005 lsd.lsd_uuid + old_namelen,
1006 sizeof(lsd.lsd_uuid) - old_namelen);
1007 else if (old_namelen < new_namelen)
1008 memmove(lsd.lsd_uuid + new_namelen,
1009 lsd.lsd_uuid + old_namelen,
1010 sizeof(lsd.lsd_uuid) - new_namelen);
1011 memcpy(lsd.lsd_uuid, ldd->ldd_fsname, new_namelen);
1012 ret = write(fd, &lsd, sizeof(lsd));
1013 if (ret != sizeof(lsd)) {
1016 fprintf(stderr, "Unable to write %s: %s\n",
1017 filepnm, strerror(ret));
1025 snprintf(cfg_dir, sizeof(cfg_dir), "%s/%s", mntpt, MOUNT_CONFIGS_DIR);
1026 dir = opendir(cfg_dir);
1032 fprintf(stderr, "Unable to opendir %s: %s\n",
1033 cfg_dir, strerror(ret));
1037 while ((dirent = readdir64(dir)) != NULL) {
1040 if (strlen(dirent->d_name) <= old_namelen)
1043 ptr = strrchr(dirent->d_name, '-');
1044 if (!ptr || (ptr - dirent->d_name) != old_namelen)
1047 if (strncmp(dirent->d_name, oldname, old_namelen) != 0)
1050 lce = lustre_cfg_entry_init(dirent->d_name);
1057 fprintf(stderr, "Fail to init item for %s: %s\n",
1058 dirent->d_name, strerror(ret));
1062 list_add(&lce->lce_list, &cfg_list);
1069 while (!list_empty(&cfg_list) && ret == 0) {
1070 lce = list_entry(cfg_list.next, struct lustre_cfg_entry,
1072 list_del(&lce->lce_list);
1073 snprintf(filepnm, sizeof(filepnm), "%s/%s", cfg_dir,
1076 /* Store the new fsname in the XATTR_TARGET_RENAME EA.
1077 * When the MGS start, it will scan config logs, and
1078 * for the ones which have the XATTR_TARGET_RENAME EA,
1079 * it will replace old fsname with the new fsname in
1080 * the config log by some shared kernel level config
1081 * logs {fork,erase} functionalities automatically. */
1082 ret = setxattr(filepnm, XATTR_TARGET_RENAME,
1084 strlen(ldd->ldd_fsname), 0);
1086 ret = unlink(filepnm);
1092 fprintf(stderr, "Fail to %s %s: %s\n",
1093 IS_MGS(ldd) ? "setxattr" : "unlink",
1094 filepnm, strerror(ret));
1097 lustre_cfg_entry_fini(lce);
1104 while (!list_empty(&cfg_list)) {
1105 lce = list_entry(cfg_list.next, struct lustre_cfg_entry,
1107 list_del(&lce->lce_list);
1108 lustre_cfg_entry_fini(lce);
1115 #ifdef HAVE_OPENSSL_SSK
1116 int load_shared_keys(struct mount_opts *mop)
1119 struct dirent *dentry;
1121 char fullpath[PATH_MAX];
1122 char *path = mop->mo_skpath;
1126 sk_init_logging(NULL, 1, 1);
1128 rc = stat(path, &sbuf);
1130 fprintf(stderr, "stat() failed for key %s: %s\n", path,
1135 /* Load individual keys or a directory of them */
1136 if (S_ISREG(sbuf.st_mode)) {
1137 return sk_load_keyfile(path);
1138 } else if (!S_ISDIR(sbuf.st_mode)) {
1139 fprintf(stderr, "Invalid shared key path: %s\n", path);
1143 dir = opendir(path);
1145 fprintf(stderr, "Unable to open shared key directory: %s\n",
1150 /* Loop through the files in the directory attempting to load them.
1151 * Any issue with loading the keyfile is treated as an error although
1152 * the loop continues until all files have been attempted. This will
1153 * allow all errors be reported at once rather then requiring
1154 * incremental corrections to fix each one and try again. */
1155 while ((dentry = readdir(dir)) != NULL) {
1156 if (strcmp(".", dentry->d_name) == 0 ||
1157 strcmp("..", dentry->d_name) == 0)
1160 rc = snprintf(fullpath, PATH_MAX, "%s/%s", path,
1162 if (rc >= PATH_MAX) {
1163 fprintf(stderr, "Path too long for %s/%s\n",
1164 path, dentry->d_name);
1169 rc = stat(fullpath, &sbuf);
1171 fprintf(stderr, "Unable to stat %s: %s\n", fullpath,
1177 if (!S_ISREG(sbuf.st_mode))
1180 rc = sk_load_keyfile(fullpath);
1182 fprintf(stderr, "Failed to load key %s\n", fullpath);
1189 #endif /* HAVE_OPENSSL_SSK */
1190 #endif /* HAVE_GSS */