Whamcloud - gitweb
LU-6661 dne: setdirstripe should fail if not supported
[fs/lustre-release.git] / lustre / utils / mount_utils.c
index 83a571f..2ec3489 100644 (file)
@@ -26,7 +26,8 @@
 /*
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
- * Copyright (c) 2012, 2013, Intel Corporation.
+ *
+ * Copyright (c) 2012, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #endif /* HAVE_CONFIG_H */
 
 #include "mount_utils.h"
+#include <mntent.h>
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
+#include <unistd.h>
 #include <config.h>
 #include <lustre_disk.h>
 #include <lustre_ver.h>
+#include <sys/mount.h>
 #include <sys/stat.h>
 #include <sys/utsname.h>
 #include <linux/loop.h>
@@ -144,6 +148,43 @@ int get_param(char *buf, char *key, char **val)
        return ENOENT;
 }
 
+int append_param(char *buf, char *key, char *val, char sep)
+{
+       int key_len, i, offset, old_val_len;
+       char *ptr = NULL, str[1024];
+
+       if (key)
+               ptr = strstr(buf, key);
+
+       /* key doesn't exist yet, so just add it */
+       if (ptr == NULL)
+               return add_param(buf, key, val);
+
+       key_len = strlen(key);
+
+       /* Copy previous values to str */
+       for (i = 0; i < sizeof(str); ++i) {
+               if ((ptr[i+key_len] == ' ') || (ptr[i+key_len] == '\0'))
+                       break;
+               str[i] = ptr[i+key_len];
+       }
+       if (i == sizeof(str))
+               return E2BIG;
+       old_val_len = i;
+
+       offset = old_val_len+key_len;
+
+       /* Move rest of buf to overwrite previous key and value */
+       for (i = 0; ptr[i+offset] != '\0'; ++i)
+               ptr[i] = ptr[i+offset];
+
+       ptr[i] = '\0';
+
+       snprintf(str+old_val_len, sizeof(str)-old_val_len, "%c%s", sep, val);
+
+       return add_param(buf, key, str);
+}
+
 char *strscat(char *dst, char *src, int buflen)
 {
        dst[buflen - 1] = 0;
@@ -450,7 +491,7 @@ struct module_backfs_ops *load_backfs_module(enum ldd_mount_type mount_type)
 
        /* This deals with duplicate ldd_mount_types resolving to same OSD layer
         * plugin (e.g. ext3/ldiskfs/ldiskfs2 all being ldiskfs) */
-       strlcpy(fsname, mt_type(mount_type), sizeof(fsname));
+       strncpy(fsname, mt_type(mount_type), sizeof(fsname));
        name = fsname + sizeof("osd-") - 1;
 
        /* change osd- to osd_ */