diff options
author | Ondrej Kozina <okozina@redhat.com> | 2015-01-28 15:58:16 +0100 |
---|---|---|
committer | Ondrej Kozina <okozina@redhat.com> | 2015-04-01 11:01:21 +0200 |
commit | 821385481bec6d78d6a58aa5622b89690e1f38c5 (patch) | |
tree | 40202b5840789a98780bb1f08c27d8b7311353f4 | |
parent | fdce374210d3b90a5b1c1bb95aad6168d2a43e63 (diff) | |
download | lvm2-821385481bec6d78d6a58aa5622b89690e1f38c5.tar.gz |
lvmpolld: introduce protocol header file
-rw-r--r-- | daemons/lvmpolld/lvmpolld-core.c | 57 | ||||
-rw-r--r-- | daemons/lvmpolld/lvmpolld-protocol.h | 47 | ||||
-rw-r--r-- | include/.symlinks.in | 1 | ||||
-rw-r--r-- | lib/lvmpolld/lvmpolld-client.c | 66 | ||||
-rw-r--r-- | tools/polling_ops.h | 2 |
5 files changed, 114 insertions, 59 deletions
diff --git a/daemons/lvmpolld/lvmpolld-core.c b/daemons/lvmpolld/lvmpolld-core.c index f58b6bf27..d47ee06fb 100644 --- a/daemons/lvmpolld/lvmpolld-core.c +++ b/daemons/lvmpolld/lvmpolld-core.c @@ -27,8 +27,8 @@ #include "daemon-server.h" #include "daemon-log.h" #include "config-util.h" +#include "lvmpolld-protocol.h" #include "lvmpolld-data-utils.h" -#include "polling_ops.h" #include "lvm-version.h" /* ??? */ #define LVMPOLLD_SOCKET DEFAULT_RUN_DIR "/lvmpolld.socket" @@ -65,11 +65,10 @@ typedef struct lvmpolld_state { const char *lvm_binary; } lvmpolld_state_t; -static const char *const const polling_ops[] = { [PVMOVE] = PVMOVE_POLL, - [CONVERT] = CONVERT_POLL, - [MERGE] = MERGE_POLL, - [MERGE_THIN] = MERGE_THIN_POLL }; - +static const char *const const polling_ops[] = { [PVMOVE] = LVMPD_REQ_PVMOVE, + [CONVERT] = LVMPD_REQ_CONVERT, + [MERGE] = LVMPD_REQ_MERGE, + [MERGE_THIN] = LVMPD_REQ_MERGE_THIN }; static void usage(const char *prog, FILE *file) { @@ -534,8 +533,8 @@ static response progress_info(client_handle h, lvmpolld_state_t *ls, request req lvmpolld_store_t *pdst; lvmpolld_lv_state_t st; response r; - const char *lvid = daemon_request_str(req, "lvid", NULL); - unsigned abort = daemon_request_int(req, "abort", 0); + const char *lvid = daemon_request_str(req, LVMPD_PARM_LVID, NULL); + unsigned abort = daemon_request_int(req, LVMPD_PARM_ABORT, 0); if (!lvid) return reply_fail(REASON_MISSING_LVID); @@ -573,18 +572,18 @@ static response progress_info(client_handle h, lvmpolld_state_t *ls, request req return reply_fail(REASON_POLLING_FAILED); if (st.polling_finished) - r = daemon_reply_simple("finished", - "data = %d", st.percent, - "reason = %s", st.cmd_state.signal ? "signal" : "retcode", - "value = %d", st.cmd_state.signal ?: st.cmd_state.retcode, + r = daemon_reply_simple(LVMPD_RESP_FINISHED, + LVMPD_PARM_DATA " = %d", st.percent, + "reason = %s", st.cmd_state.signal ? LVMPD_REAS_SIGNAL : LVMPD_REAS_RETCODE, + LVMPD_PARM_VALUE " = %d", st.cmd_state.signal ?: st.cmd_state.retcode, NULL); else - r = daemon_reply_simple("inprogress", - "data = %d", st.percent, + r = daemon_reply_simple(LVMPD_RESP_IN_PROGRESS, + LVMPD_PARM_DATA " = %d", st.percent, NULL); } else - r = daemon_reply_simple("not_found", NULL); + r = daemon_reply_simple(LVMPD_RESP_NOT_FOUND, NULL); return r; } @@ -598,7 +597,7 @@ static lvmpolld_lv_t *construct_pdlv(request req, lvmpolld_state_t *ls, { const char **cmdargv; lvmpolld_lv_t *pdlv; - unsigned handle_missing_pvs = daemon_request_int(req, "handle_missing_pvs", 0); + unsigned handle_missing_pvs = daemon_request_int(req, LVMPD_PARM_HANDLE_MISSING_PVS, 0); pdlv = pdlv_create(ls, lvid, vgname, type, interval, 2 * uinterval, pdst, (abort ? NULL : parse_line_for_percents), @@ -642,11 +641,11 @@ static response poll_init(client_handle h, lvmpolld_state_t *ls, request req, en lvmpolld_store_t *pdst; unsigned uinterval; - const char *lvid = daemon_request_str(req, "lvid", NULL); - const char *interval = daemon_request_str(req, "interval", NULL); - const char *vgname = daemon_request_str(req, "vgname", NULL); - unsigned abort = daemon_request_int(req, "abort", 0); - unsigned background = daemon_request_int(req, "background", 1); + const char *lvid = daemon_request_str(req, LVMPD_PARM_LVID, NULL); + const char *interval = daemon_request_str(req, LVMPD_PARM_INTERVAL, NULL); + const char *vgname = daemon_request_str(req, LVMPD_PARM_VGNAME, NULL); + unsigned abort = daemon_request_int(req, LVMPD_PARM_ABORT, 0); + unsigned background = daemon_request_int(req, LVMPD_PARM_BACKGROUND, 1); assert(type < POLL_TYPE_MAX); @@ -713,7 +712,7 @@ static response poll_init(client_handle h, lvmpolld_state_t *ls, request req, en pdst_unlock(pdst); - return daemon_reply_simple("OK", NULL); + return daemon_reply_simple(LVMPD_RESP_OK, NULL); } static response handler(struct daemon_state s, client_handle h, request r) @@ -721,15 +720,15 @@ static response handler(struct daemon_state s, client_handle h, request r) lvmpolld_state_t *ls = s.private; const char *rq = daemon_request_str(r, "request", "NONE"); - if (!strcmp(rq, PVMOVE_POLL)) + if (!strcmp(rq, LVMPD_REQ_PVMOVE)) return poll_init(h, ls, r, PVMOVE); - if (!strcmp(rq, CONVERT_POLL)) + if (!strcmp(rq, LVMPD_REQ_CONVERT)) return poll_init(h, ls, r, CONVERT); - if (!strcmp(rq, MERGE_POLL)) + if (!strcmp(rq, LVMPD_REQ_MERGE)) return poll_init(h, ls, r, MERGE); - if (!strcmp(rq, MERGE_THIN_POLL)) + if (!strcmp(rq, LVMPD_REQ_MERGE_THIN)) return poll_init(h, ls, r, MERGE_THIN); - if (!strcmp(rq, "progress_info")) + if (!strcmp(rq, LVMPD_REQ_PROGRESS)) return progress_info(h, ls, r); return reply_fail(REASON_REQ_NOT_IMPLEMENTED); @@ -743,11 +742,11 @@ int main(int argc, char *argv[]) .daemon_fini = fini, .daemon_init = init, .handler = handler, - .name = "lvmpolld", + .name = LVMPOLLD_PROTOCOL, .pidfile = getenv("LVM_LVMPOLLD_PIDFILE") ?: LVMPOLLD_PIDFILE, .private = &ls, .protocol = "lvmpolld", - .protocol_version = 1, + .protocol_version = LVMPOLLD_PROTOCOL_VERSION, .socket_path = getenv("LVM_LVMPOLLD_SOCKET") ?: LVMPOLLD_SOCKET, }; diff --git a/daemons/lvmpolld/lvmpolld-protocol.h b/daemons/lvmpolld/lvmpolld-protocol.h new file mode 100644 index 000000000..423376711 --- /dev/null +++ b/daemons/lvmpolld/lvmpolld-protocol.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * This file is part of LVM2. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _LVM_LVMPOLLD_PROTOCOL_H +#define _LVM_LVMPOLLD_PROTOCOL_H + +#include "polling_ops.h" + +#define LVMPOLLD_PROTOCOL "lvmpolld" +#define LVMPOLLD_PROTOCOL_VERSION 1 + +#define LVMPD_REQ_CONVERT CONVERT_POLL +#define LVMPD_REQ_MERGE MERGE_POLL +#define LVMPD_REQ_MERGE_THIN MERGE_THIN_POLL +#define LVMPD_REQ_PROGRESS "progress_info" +#define LVMPD_REQ_PVMOVE PVMOVE_POLL + +#define LVMPD_PARM_ABORT "abort" +#define LVMPD_PARM_BACKGROUND "background" +#define LVMPD_PARM_DATA "data" /* progress data */ +#define LVMPD_PARM_HANDLE_MISSING_PVS "handle_missing_pvs" +#define LVMPD_PARM_INTERVAL "interval" +#define LVMPD_PARM_LVID "lvid" +#define LVMPD_PARM_VALUE "value" /* either retcode or signal value */ +#define LVMPD_PARM_VGNAME "vgname" + +#define LVMPD_RESP_FAILED "failed" +#define LVMPD_RESP_FINISHED "finished" +#define LVMPD_RESP_IN_PROGRESS "in_progress" +#define LVMPD_RESP_NOT_FOUND "not_found" +#define LVMPD_RESP_OK "OK" + +#define LVMPD_REAS_RETCODE "retcode" /* lvm cmd ret code */ +#define LVMPD_REAS_SIGNAL "signal" /* lvm cmd terminating singal */ + +#endif /* _LVM_LVMPOLLD_PROTOCOL_H */ diff --git a/include/.symlinks.in b/include/.symlinks.in index cfca85927..b8f3a1e12 100644 --- a/include/.symlinks.in +++ b/include/.symlinks.in @@ -2,6 +2,7 @@ @top_srcdir@/daemons/dmeventd/libdevmapper-event.h @top_srcdir@/daemons/lvmetad/lvmetad-client.h @top_srcdir@/daemons/lvmpolld/lvmpolld-client.h +@top_srcdir@/daemons/lvmpolld/lvmpolld-protocol.h @top_srcdir@/liblvm/lvm2app.h @top_srcdir@/lib/activate/activate.h @top_srcdir@/lib/activate/targets.h diff --git a/lib/lvmpolld/lvmpolld-client.c b/lib/lvmpolld/lvmpolld-client.c index d4321c484..2b0b14c1a 100644 --- a/lib/lvmpolld/lvmpolld-client.c +++ b/lib/lvmpolld/lvmpolld-client.c @@ -18,7 +18,7 @@ #include "lvmpolld-client.h" #include "daemon-io.h" #include "metadata-exported.h" -#include "polling_ops.h" +#include "lvmpolld-protocol.h" #include "toolcontext.h" struct progress_info { @@ -40,8 +40,8 @@ static daemon_handle _lvmpolld_connect(const char *socket) daemon_info lvmpolld_info = { .path = "lvmpolld", .socket = socket ?: LVMPOLLD_SOCKET, - .protocol = "lvmpolld", - .protocol_version = 1 + .protocol = LVMPOLLD_PROTOCOL, + .protocol_version = LVMPOLLD_PROTOCOL_VERSION }; return daemon_open(lvmpolld_info); @@ -82,12 +82,15 @@ static struct progress_info _request_progress_info(const char *uuid, unsigned ab { daemon_reply repl; struct progress_info ret = { .error = 1, .finished = 1 }; - daemon_request req = daemon_request_make("progress_info"); + daemon_request req = daemon_request_make(LVMPD_REQ_PROGRESS); - if (!daemon_request_extend(req, "lvid = %s", uuid, - "abort = %d", abort, - NULL)) { - log_error("failed to create 'progress_info' request"); + if (!daemon_request_extend(req, LVMPD_PARM_LVID " = %s", uuid, NULL)) { + log_error("failed to create " LVMPD_REQ_PROGRESS " request"); + goto out_req; + } + + if (abort && !daemon_request_extend(req, LVMPD_PARM_ABORT " = %d", abort, NULL)) { + log_error("failed to create " LVMPD_REQ_PROGRESS " request"); goto out_req; } @@ -97,22 +100,22 @@ static struct progress_info _request_progress_info(const char *uuid, unsigned ab goto out_repl; } - if (!strcmp(daemon_reply_str(repl, "response", ""), "inprogress")) { + if (!strcmp(daemon_reply_str(repl, "response", ""), LVMPD_RESP_IN_PROGRESS)) { ret.percents = (dm_percent_t) daemon_reply_int(repl, "data", 0); ret.finished = 0; ret.error = 0; - } else if (!strcmp(daemon_reply_str(repl, "response", ""), "finished")) { - ret.percents = (dm_percent_t) daemon_reply_int(repl, "data", 0); - if (!strcmp(daemon_reply_str(repl, "reason", ""), "signal")) - ret.cmd_signal = daemon_reply_int(repl, "value", 0); + } else if (!strcmp(daemon_reply_str(repl, "response", ""), LVMPD_RESP_FINISHED)) { + ret.percents = (dm_percent_t) daemon_reply_int(repl, LVMPD_PARM_DATA, 0); + if (!strcmp(daemon_reply_str(repl, "reason", ""), LVMPD_REAS_SIGNAL)) + ret.cmd_signal = daemon_reply_int(repl, LVMPD_PARM_VALUE, 0); else - ret.cmd_retcode = daemon_reply_int(repl, "value", -1); + ret.cmd_retcode = daemon_reply_int(repl, LVMPD_PARM_VALUE, -1); ret.error = 0; - } else if (!strcmp(daemon_reply_str(repl, "response", ""), "not_found")) { + } else if (!strcmp(daemon_reply_str(repl, "response", ""), LVMPD_RESP_NOT_FOUND)) { log_verbose("lvmpolld: no polling operation in progress regarding LV %s", uuid); ret.error = 0; - } else if (!strcmp(daemon_reply_str(repl, "response", ""), "failed")) - log_error("failed to receive progress data: The reason: %s", + } else if (!strcmp(daemon_reply_str(repl, "response", ""), LVMPD_RESP_FAILED)) + log_error("failed to receive progress data: %s", daemon_reply_str(repl, "reason", "<empty>")); else log_error("Unexpected lvmpolld response: %s", @@ -152,34 +155,37 @@ static int _process_poll_init(const struct cmd_context *cmd, const char *poll_ty } req = daemon_request_make(poll_type); - if (!daemon_request_extend(req, "lvid = %s", uuid, - "vgname = %s", vgname, - "interval = %s", str, - "cmdline = %s", cmd->cmd_line, + if (!daemon_request_extend(req, LVMPD_PARM_LVID " = %s", uuid, + LVMPD_PARM_VGNAME " = %s", vgname, + LVMPD_PARM_INTERVAL " = %s", str, + "cmdline = %s", cmd->cmd_line, /* FIXME: debug param only */ NULL)) { log_error("failed to create %s request", poll_type); goto out_req; } - if (abort && !(daemon_request_extend(req, "abort = %d", abort, NULL))) { + if (abort && + !(daemon_request_extend(req, LVMPD_PARM_ABORT " = %d", abort, NULL))) { log_error("failed to create %s request" , poll_type); goto out_req; } - if (!background && !(daemon_request_extend(req, "background = %d", background, NULL))) { + if (!background && + !(daemon_request_extend(req, LVMPD_PARM_BACKGROUND " = %d", background, NULL))) { log_error("failed to create %s request" , poll_type); goto out_req; } - if (cmd->handles_missing_pvs && !(daemon_request_extend(req, "handle_missing_pvs = %d", cmd->handles_missing_pvs, NULL))) { + if (cmd->handles_missing_pvs && + !(daemon_request_extend(req, LVMPD_PARM_HANDLE_MISSING_PVS " = %d", + cmd->handles_missing_pvs, NULL))) { log_error("failed to create %s request" , poll_type); goto out_req; } rep = daemon_send(_lvmpolld, req); - if (!strcmp(daemon_reply_str(rep, "response", ""), "OK")) - /* OK */ + if (!strcmp(daemon_reply_str(rep, "response", ""), LVMPD_RESP_OK)) r = 1; else { if (rep.error) @@ -216,18 +222,18 @@ int lvmpolld_poll_init(const struct cmd_context *cmd, const char *vgname, const if (lv_type & PVMOVE) { log_verbose("lvmpolld: pvmove%s", abort ? "--abort" : ""); - r = _process_poll_init(cmd, PVMOVE_POLL, vgname, uuid, background, interval, abort); + r = _process_poll_init(cmd, LVMPD_REQ_PVMOVE, vgname, uuid, background, interval, abort); } else if (lv_type & CONVERTING) { log_verbose("lvmpolld: convert mirror"); - r = _process_poll_init(cmd, CONVERT_POLL, vgname, uuid, background, interval, 0); + r = _process_poll_init(cmd, LVMPD_REQ_CONVERT, vgname, uuid, background, interval, 0); } else if (lv_type & MERGING) { if (lv_type & SNAPSHOT) { log_verbose("lvmpolld: Merge snapshot"); - r = _process_poll_init(cmd, MERGE_POLL, vgname, uuid, background, interval, 0); + r = _process_poll_init(cmd, LVMPD_REQ_MERGE, vgname, uuid, background, interval, 0); } else if (lv_type & THIN_VOLUME) { log_verbose("lvmpolld: Merge thin snapshot"); - r = _process_poll_init(cmd, MERGE_THIN_POLL, vgname, uuid, background, interval, 0); + r = _process_poll_init(cmd, LVMPD_REQ_MERGE_THIN, vgname, uuid, background, interval, 0); } else { log_error(INTERNAL_ERROR "Unsupported poll operation"); diff --git a/tools/polling_ops.h b/tools/polling_ops.h index 1733ea3c3..87541d227 100644 --- a/tools/polling_ops.h +++ b/tools/polling_ops.h @@ -15,6 +15,8 @@ #ifndef _LVM_TOOL_POLLING_OPS_H #define _LVM_TOOL_POLLING_OPS_H +/* this file is also part of lvmpolld protocol */ + #define PVMOVE_POLL "pvmove" #define CONVERT_POLL "convert" #define MERGE_POLL "merge" |