lvm2/use-mirrortype-asdefault-whenclvmdrunning.patch

55 lines
1.7 KiB
Diff

---
tools/lvcreate.c | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -834,6 +834,28 @@ static int _read_activation_params(struc
return 1;
}
+static int clvmd_daemon_is_running(void)
+{
+ int fd;
+ struct flock lock;
+
+ if((fd = open(CLVMD_PIDFILE, O_RDONLY)) < 0)
+ return 0;
+
+ lock.l_type = F_WRLCK;
+ lock.l_start = 0;
+ lock.l_whence = SEEK_SET;
+ lock.l_len = 0;
+ if (fcntl(fd, F_GETLK, &lock) < 0) {
+ /* errors with fcntl */
+ close(fd);
+ return 0;
+ }
+
+ close(fd);
+ return (lock.l_type == F_UNLCK) ? 0 : 1;
+}
+
static int _lvcreate_params(struct lvcreate_params *lp,
struct lvcreate_cmdline_params *lcp,
struct cmd_context *cmd,
@@ -860,14 +882,16 @@ static int _lvcreate_params(struct lvcre
/* Set default segtype - remember, '-m 0' implies stripe. */
if (arg_count(cmd, mirrors_ARG) &&
- arg_uint_value(cmd, mirrors_ARG, 0))
+ arg_uint_value(cmd, mirrors_ARG, 0)) {
if (arg_uint_value(cmd, arg_count(cmd, stripes_long_ARG) ?
stripes_long_ARG : stripes_ARG, 1) > 1) {
segtype_str = find_config_tree_str(cmd, global_raid10_segtype_default_CFG, NULL);;
} else {
segtype_str = find_config_tree_str(cmd, global_mirror_segtype_default_CFG, NULL);
}
- else if (arg_count(cmd, thin_ARG) || arg_count(cmd, thinpool_ARG))
+ if(clvmd_daemon_is_running())
+ segtype_str = "mirror";
+ } else if (arg_count(cmd, thin_ARG) || arg_count(cmd, thinpool_ARG))
segtype_str = "thin";
else if (arg_count(cmd, cache_ARG) || arg_count(cmd, cachepool_ARG))
segtype_str = "cache";