Package: mhddfs
Version: 0.1.39

This is not a bug but a feature request.  I would like to submit the attached 
patch file.  This adds an option, use_parent, to enforce creation of new files 
and directories on the file system where the parent folder originally existed.

Our use case is:
1. We are combining two large file systems from old servers onto one server by 
moving the disks from the second server to the first.
2. This first server has space for the additional disks.
3. In case someone needs to write new files to directories on the second file 
system, we want those files to be created in the second file system and not the 
first.
4. In case someone needs to write new files to directories on the first file 
system, we want those files to be created in the first file system and not the 
second.

So, basing the final target on available free space was not ideal for us.  
After the patch is applied, you would mount dirs. As follows:

mhddfs -o use_parent=1 /first /second /newmountpoint

Patch:
diff -aurb mhddfs-0.1.39/src/main.c mhddfs-0.1.39_usep/src/main.c
--- mhddfs-0.1.39/src/main.c    2012-06-17 09:09:56.000000000 -0500
+++ mhddfs-0.1.39_usep/src/main.c       2015-06-18 08:58:53.203123329 -0500
@@ -302,10 +302,26 @@
 
        mhdd_debug(MHDD_INFO, "mhdd_internal_open: new file %s\n", file);
 
+       if (mhdd.use_parent == 1)
+       {
+               mhdd_debug(MHDD_INFO, "mhdd_internal_open: find parent path of 
%s\n", file);
+               char *newparent = get_parent_path(file);
+               mhdd_debug(MHDD_INFO, "mhdd_internal_open: new file path %s\n", 
newparent);
+               if ((dir_id = find_path_id(newparent)) < 0)
+               {
+                       errno = ENOSPC;
+                       return -errno;
+               }
+       }
+       else
+       {
        if ((dir_id = get_free_dir()) < 0) {
                errno = ENOSPC;
                return -errno;
        }
+       }
+
+       //mhdd_debug(MHDD_INFO, "mhdd_internal_open: path,dir_id is %s, %i\n", 
file, dir_id);
 
        create_parent_dirs(dir_id, file);
        path = create_path(mhdd.dirs[dir_id], file);
@@ -513,6 +529,7 @@
 static int mhdd_mkdir(const char * path, mode_t mode)
 {
        mhdd_debug(MHDD_MSG, "mhdd_mkdir: %s mode = %04X\n", path, mode);
+       int dir_id;
 
        if (find_path_id(path) != -1) {
                errno = EEXIST;
@@ -530,9 +547,25 @@
                errno = EFAULT;
                return -errno;
        }
+
+       if (mhdd.use_parent == 1)
+       {
+               mhdd_debug(MHDD_INFO, "mhdd_mkdir: find parent path of %s\n", 
path);
+               char *newparent = get_parent_path(path);
+               mhdd_debug(MHDD_INFO, "mhdd_mkdir: new file path %s\n", 
newparent);
+               if ((dir_id = find_path_id(newparent)) < 0)
+               {
+                       errno = ENOSPC;
+                       return -errno;
+               }
+       }
+       else
+       {
+               dir_id = get_free_dir();
+       }
+
        free(parent);
 
-       int dir_id = get_free_dir();
        if (dir_id<0) {
                errno = ENOSPC;
                return -errno;
@@ -557,7 +590,6 @@
        free(name);
        return -errno;
 }
-
 // rmdir
 static int mhdd_rmdir(const char * path)
 {
diff -aurb mhddfs-0.1.39/src/parse_options.c 
mhddfs-0.1.39_usep/src/parse_options.c
--- mhddfs-0.1.39/src/parse_options.c   2012-06-17 09:09:56.000000000 -0500
+++ mhddfs-0.1.39_usep/src/parse_options.c      2015-06-17 14:57:58.994034735 
-0500
@@ -50,11 +50,14 @@
    more than 100 is in bytes */
 #define DEFAULT_MLIMIT ( 4l * 1024 * 1024 * 1024 )
 #define MINIMUM_MLIMIT ( 50l * 1024 * 1024 )
+#define DEFAULT_USE_PARENT 0
+#define USE_PARENT 1
 
 static struct fuse_opt mhddfs_opts[]={
        MHDDFS_OPT("mlimit=%s",   mlimit_str, 0),
        MHDDFS_OPT("logfile=%s",  debug_file, 0),
        MHDDFS_OPT("loglevel=%d", loglevel,   0),
+       MHDDFS_OPT("use_parent=%d", use_parent, 0),
 
        FUSE_OPT_KEY("-V",        MHDD_VERSION_OPT),
        FUSE_OPT_KEY("--version", MHDD_VERSION_OPT),
@@ -306,6 +309,11 @@
                fprintf(stderr, "mhddfs: move size limit %lld bytes\n",
                                (long long)mhdd.move_limit);
 
+       if (mhdd.use_parent == 1)
+               fprintf(stderr, "mhddfs: use_parent TRUE\n");
+       else
+               fprintf(stderr, "mhddfs: use_parent FALSE\n");
+
        mhdd_debug(MHDD_MSG, " >>>>> mhdd " VERSION " started <<<<<\n");
 
        return args;
diff -aurb mhddfs-0.1.39/src/parse_options.h 
mhddfs-0.1.39_usep/src/parse_options.h
--- mhddfs-0.1.39/src/parse_options.h   2012-06-17 09:09:56.000000000 -0500
+++ mhddfs-0.1.39_usep/src/parse_options.h      2015-06-17 14:54:18.554295708 
-0500
@@ -38,6 +38,8 @@
        char  *mlimit_str;  // mlimit string
 
        int   loglevel;
+
+       int use_parent;
 };
 
 extern struct mhdd_config mhdd;
diff -aurb mhddfs-0.1.39/src/tools.c mhddfs-0.1.39_usep/src/tools.c
--- mhddfs-0.1.39/src/tools.c   2012-06-17 09:09:56.000000000 -0500
+++ mhddfs-0.1.39_usep/src/tools.c      2015-06-18 08:07:40.427872598 -0500
@@ -440,6 +440,7 @@
        int i;
        struct stat st;
 
+       mhdd_debug(MHDD_DEBUG,"find_path_id: file=%s\n",file);
        for (i=0; i<mhdd.cdirs; i++)
        {
                char *path=create_path(mhdd.dirs[i], file);
diff -aurb mhddfs-0.1.39/src/usage.c mhddfs-0.1.39_usep/src/usage.c
--- mhddfs-0.1.39/src/usage.c   2012-06-17 09:09:56.000000000 -0500
+++ mhddfs-0.1.39_usep/src/usage.c      2015-06-17 08:08:56.766155891 -0500
@@ -40,6 +40,10 @@
                "                0 - debug\n"
                "                1 - info\n"
                "                2 - default messages\n"
+               "  use_parent=x - Use parent directory of the same file 
system\n"
+               "                 when creating new files.\n"
+               "                  0 - no (default)\n"
+               "                  1 - yes\n"
                "\n"
                " see fusermount(1) for information about other options\n"
                "";



--------------------------------------------------------------------------------
Privileged, Proprietary and/or Confidential Information may be contained in
this electronic message.  If you are not the intended recipient, you should
not copy it, re-transmit it, use it or disclose its contents, but should
kindly return to the sender immediately and delete your copy from your system.
Gulf Interstate Engineering Company does not accept responsibility for
changes made to this electronic message or its attachments. 


--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to