Whamcloud - gitweb
LU-1581 utils: osd_write_ldd() wrapper
[fs/lustre-release.git] / lustre / utils / mount_utils_ldiskfs.c
index 637c92c..e334f58 100644 (file)
@@ -87,7 +87,7 @@ extern char *progname;
 #define EXT3_DIRENT_SIZE                DUMMY_FILE_NAME_LEN
 
 /* Write the server config files */
-int write_local_files(struct mkfs_opts *mop)
+int ldiskfs_write_ldd(struct mkfs_opts *mop)
 {
        char mntpt[] = "/tmp/mntXXXXXX";
        char filepnm[128];
@@ -156,12 +156,11 @@ out_rmdir:
        return ret;
 }
 
-int read_local_files(struct mkfs_opts *mop)
+int ldiskfs_read_ldd(char *dev, struct lustre_disk_data *mo_ldd)
 {
        char tmpdir[] = "/tmp/dirXXXXXX";
        char cmd[PATH_MAX];
        char filepnm[128];
-       char *dev;
        FILE *filep;
        int ret = 0;
        int cmdsz = sizeof(cmd);
@@ -173,8 +172,6 @@ int read_local_files(struct mkfs_opts *mop)
                return errno;
        }
 
-       dev = mop->mo_device;
-
        /* TODO: it's worth observing the get_mountdata() function that is
           in mount_utils.c for getting the mountdata out of the
           filesystem */
@@ -193,7 +190,7 @@ int read_local_files(struct mkfs_opts *mop)
        if (filep) {
                size_t num_read;
                vprint("Reading %s\n", MOUNT_DATA_FILE);
-               num_read = fread(&mop->mo_ldd, sizeof(mop->mo_ldd), 1, filep);
+               num_read = fread(mo_ldd, sizeof(*mo_ldd), 1, filep);
                if (num_read < 1 && ferror(filep)) {
                        fprintf(stderr, "%s: Unable to read from file %s: %s\n",
                                progname, filepnm, strerror(errno));
@@ -277,31 +274,26 @@ static int file_in_dev(char *file_name, char *dev_name)
 }
 
 /* Check whether the device has already been used with lustre */
-int is_lustre_target(struct mkfs_opts *mop)
+int ldiskfs_is_lustre(char *dev, unsigned *mount_type)
 {
-       int rc;
+       int ret;
 
-       vprint("checking for existing Lustre data: ");
-
-       if ((rc = file_in_dev(MOUNT_DATA_FILE, mop->mo_device))) {
-               vprint("found %s\n",
-                      (rc == 1) ? MOUNT_DATA_FILE : "extents");
-               /* in the -1 case, 'extents' means this really IS a lustre
-                  target */
-               return rc;
+       ret = file_in_dev(MOUNT_DATA_FILE, dev);
+       if (ret) {
+               /* in the -1 case, 'extents' means IS a lustre target */
+               *mount_type = LDD_MT_LDISKFS;
+               return 1;
        }
 
-       if ((rc = file_in_dev(LAST_RCVD, mop->mo_device))) {
-               vprint("found %s\n", LAST_RCVD);
-               return rc;
+       ret = file_in_dev(LAST_RCVD, dev);
+       if (ret) {
+               *mount_type = LDD_MT_LDISKFS;
+               return 1;
        }
 
-       vprint("not found\n");
-       return 0; /* The device is not a lustre target. */
+       return 0;
 }
 
-
-
 /* Check if a certain feature is supported by e2fsprogs.
  * Firstly we try to use "debugfs supported_features" command to check if
  * the feature is supported. If this fails we try to set this feature with
@@ -484,7 +476,7 @@ static char *moveopts_to_end(char *start)
 }
 
 /* Build fs according to type */
-int make_lustre_backfs(struct mkfs_opts *mop)
+int ldiskfs_make_lustre(struct mkfs_opts *mop)
 {
        __u64 device_sz = mop->mo_device_sz, block_count = 0;
        char mkfs_cmd[PATH_MAX];
@@ -731,6 +723,28 @@ int make_lustre_backfs(struct mkfs_opts *mop)
        return ret;
 }
 
+int ldiskfs_prepare_lustre(struct mkfs_opts *mop,
+                          char *default_mountopts, int default_len,
+                          char *always_mountopts, int always_len)
+{
+       struct lustre_disk_data *ldd = &mop->mo_ldd;
+       int ret;
+
+       /* Set MO_IS_LOOP to indicate a loopback device is needed */
+       ret = is_block(mop->mo_device);
+       if (ret < 0) {
+               return errno;
+       } else if (ret == 0) {
+               mop->mo_flags |= MO_IS_LOOP;
+       }
+
+       strscat(default_mountopts, ",errors=remount-ro", default_len);
+       if (IS_MDT(ldd) || IS_MGS(ldd))
+               strscat(always_mountopts, ",user_xattr", always_len);
+
+       return 0;
+}
+
 /* return canonicalized absolute pathname, even if the target file does not
  * exist, unlike realpath */
 static char *absolute_path(char *devname)