Imported Upstream version 0.7.5
[platform/upstream/multipath-tools.git] / libmultipath / devmapper.c
index fcac6bc..607aea8 100644 (file)
 #include <sys/types.h>
 #include <time.h>
 
+#define FREE_CONST(p) do { free((void*)(unsigned long)p); p = NULL; } while(0)
 #define MAX_WAIT 5
 #define LOOPS_PER_SEC 5
 
-#define UUID_PREFIX "mpath-"
-#define UUID_PREFIX_LEN 6
-
 static int dm_conf_verbosity;
 
 #ifdef LIBDM_API_DEFERRED
@@ -378,7 +376,7 @@ static uint16_t build_udev_flags(const struct multipath *mpp, int reload)
        /* DM_UDEV_DISABLE_LIBRARY_FALLBACK is added in dm_addmap */
        return  (mpp->skip_kpartx == SKIP_KPARTX_ON ?
                 MPATH_UDEV_NO_KPARTX_FLAG : 0) |
-               (mpp->nr_active == 0 ?
+               ((mpp->nr_active == 0 || mpp->ghost_delay_tick > 0)?
                 MPATH_UDEV_NO_PATHS_FLAG : 0) |
                (reload && !mpp->force_udev_reload ?
                 MPATH_UDEV_RELOAD_FLAG : 0);
@@ -586,7 +584,7 @@ is_mpath_part(const char *part_name, const char *map_name)
        return 0;
 }
 
-int dm_get_status(char *name, char *outstatus)
+int dm_get_status(const char *name, char *outstatus)
 {
        int r = 1;
        struct dm_task *dmt;
@@ -810,7 +808,7 @@ int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove,
        if (need_suspend &&
            !dm_get_map(mapname, &mapsize, params) &&
            strstr(params, "queue_if_no_path")) {
-               if (!dm_queue_if_no_path((char *)mapname, 0))
+               if (!dm_queue_if_no_path(mapname, 0))
                        queue_if_no_path = 1;
                else
                        /* Leave queue_if_no_path alone if unset failed */
@@ -853,7 +851,7 @@ int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove,
        } while (retries-- > 0);
 
        if (queue_if_no_path == 1)
-               dm_queue_if_no_path((char *)mapname, 1);
+               dm_queue_if_no_path(mapname, 1);
 
        return 1;
 }
@@ -941,7 +939,7 @@ out:
 }
 
 int
-dm_fail_path(char * mapname, char * path)
+dm_fail_path(const char * mapname, char * path)
 {
        char message[32];
 
@@ -952,7 +950,7 @@ dm_fail_path(char * mapname, char * path)
 }
 
 int
-dm_reinstate_path(char * mapname, char * path)
+dm_reinstate_path(const char * mapname, char * path)
 {
        char message[32];
 
@@ -963,7 +961,7 @@ dm_reinstate_path(char * mapname, char * path)
 }
 
 int
-dm_queue_if_no_path(char *mapname, int enable)
+dm_queue_if_no_path(const char *mapname, int enable)
 {
        char *message;
 
@@ -976,7 +974,7 @@ dm_queue_if_no_path(char *mapname, int enable)
 }
 
 static int
-dm_groupmsg (char * msg, char * mapname, int index)
+dm_groupmsg (const char * msg, const char * mapname, int index)
 {
        char message[32];
 
@@ -987,19 +985,19 @@ dm_groupmsg (char * msg, char * mapname, int index)
 }
 
 int
-dm_switchgroup(char * mapname, int index)
+dm_switchgroup(const char * mapname, int index)
 {
        return dm_groupmsg("switch", mapname, index);
 }
 
 int
-dm_enablegroup(char * mapname, int index)
+dm_enablegroup(const char * mapname, int index)
 {
        return dm_groupmsg("enable", mapname, index);
 }
 
 int
-dm_disablegroup(char * mapname, int index)
+dm_disablegroup(const char * mapname, int index)
 {
        return dm_groupmsg("disable", mapname, index);
 }
@@ -1083,7 +1081,7 @@ out:
 }
 
 int
-dm_geteventnr (char *name)
+dm_geteventnr (const char *name)
 {
        struct dm_info info;
 
@@ -1142,7 +1140,7 @@ dm_mapname(int major, int minor)
 
        map = dm_task_get_name(dmt);
        if (map && strlen(map))
-               response = STRDUP((char *)dm_task_get_name(dmt));
+               response = STRDUP((const char *)dm_task_get_name(dmt));
 
        dm_task_destroy(dmt);
        return response;
@@ -1267,7 +1265,7 @@ cancel_remove_partmap (const char *name, void *unused)
 }
 
 static int
-dm_get_deferred_remove (char * mapname)
+dm_get_deferred_remove (const char * mapname)
 {
        struct dm_info info;
 
@@ -1415,10 +1413,10 @@ out:
        return r;
 }
 
-void dm_reassign_deps(char *table, char *dep, char *newdep)
+void dm_reassign_deps(char *table, const char *dep, const char *newdep)
 {
-       char *p, *n;
-       char *newtable;
+       char *n;
+       const char *p, *newtable;
 
        newtable = strdup(table);
        if (!newtable)
@@ -1429,7 +1427,7 @@ void dm_reassign_deps(char *table, char *dep, char *newdep)
        n += strlen(newdep);
        p += strlen(dep);
        strcat(n, p);
-       free(newtable);
+       FREE_CONST(newtable);
 }
 
 int dm_reassign_table(const char *name, char *old, char *new)