]>
Commit | Line | Data |
---|---|---|
6ae08450 JR |
1 | From e5d7c7070358a5db8b849c8c5886e67881fe8906 Mon Sep 17 00:00:00 2001 |
2 | From: Chris Leech <cleech@redhat.com> | |
3 | Date: Fri, 7 Dec 2012 17:01:42 -0800 | |
4 | Subject: [PATCH 47/47] iscsiadm, iscsid: newroot command to survive | |
5 | switch_root | |
6 | ||
7 | When started from initramfs, iscsid needs to be able to chroot itself | |
8 | to the runtime filesystem before the switch_root occurs. In the | |
9 | initramfs "iscsiadm --newroot {root fs mount before switch}" should be | |
10 | called before the switch_root. | |
11 | ||
12 | Signed-off-by: Chris Leech <cleech@redhat.com> | |
13 | --- | |
14 | usr/iscsiadm.c | 30 ++++++++++++++++++++++++++++++ | |
15 | usr/mgmt_ipc.c | 11 +++++++++++ | |
16 | usr/mgmt_ipc.h | 6 +++++- | |
17 | 3 files changed, 46 insertions(+), 1 deletion(-) | |
18 | ||
19 | diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c | |
20 | index da0a3ec..af6d607 100644 | |
21 | --- a/usr/iscsiadm.c | |
22 | +++ b/usr/iscsiadm.c | |
23 | @@ -117,6 +117,7 @@ static struct option const long_options[] = | |
24 | {"interval", required_argument, NULL, 'i'}, | |
25 | {"flashnode_idx", optional_argument, NULL, 'x'}, | |
26 | {"portal_type", optional_argument, NULL, 'A'}, | |
27 | + {"newroot", required_argument, NULL, 0}, | |
28 | {NULL, 0, NULL, 0}, | |
29 | }; | |
30 | static char *short_options = "RlDVhm:a:b:c:C:p:P:T:H:i:I:U:k:L:d:r:n:v:o:sSt:ux:A:"; | |
31 | @@ -137,6 +138,7 @@ iscsiadm -m session [ -hV ] [ -d debug_level ] [ -P printlevel] [ -r sessionid | |
32 | iscsiadm -m iface [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -I ifacename | -H hostno|MAC ] [ [ -o operation ] [ -n name ] [ -v value ] ] [ -C ping [ -a ip ] [ -b packetsize ] [ -c count ] [ -i interval ] ]\n\ | |
33 | iscsiadm -m fw [ -d debug_level ] [ -l ]\n\ | |
34 | iscsiadm -m host [ -P printlevel ] [ -H hostno|MAC ] [ [ -C chap [ -x chap_tbl_idx ] ] | [ -C flashnode [ -A portal_type ] [ -x flashnode_idx ] ] | [ -C stats ] ] [ [ -o operation ] [ -n name ] [ -v value ] ] \n\ | |
35 | +iscsiadm --newroot switch_root_path\n\ | |
36 | iscsiadm -k priority\n"); | |
37 | } | |
38 | exit(status); | |
39 | @@ -278,6 +280,22 @@ static void kill_iscsid(int priority) | |
40 | } | |
41 | } | |
42 | ||
43 | +static void do_newroot(char *newroot) | |
44 | +{ | |
45 | + iscsiadm_req_t req; | |
46 | + iscsiadm_rsp_t rsp; | |
47 | + int rc; | |
48 | + | |
49 | + memset(&req, 0, sizeof(req)); | |
50 | + req.command = MGMT_IPC_NEWROOT; | |
51 | + strncpy(req.u.newroot.path, newroot, PATH_MAX); | |
52 | + rc = iscsid_exec_req(&req, &rsp, 0); | |
53 | + if (rc) { | |
54 | + iscsi_err_print_msg(rc); | |
55 | + log_error("Could not send NEWROOT command"); | |
56 | + } | |
57 | +} | |
58 | + | |
59 | /* | |
60 | * TODO: we can display how the ifaces are related to node records. | |
61 | * And we can add a scsi_host mode which would display how | |
62 | @@ -2800,6 +2818,7 @@ main(int argc, char **argv) | |
63 | { | |
64 | char *ip = NULL, *name = NULL, *value = NULL; | |
65 | char *targetname = NULL, *group_session_mgmt_mode = NULL; | |
66 | + char *newroot = NULL; | |
67 | int ch, longindex, mode=-1, port=-1, do_login=0, do_rescan=0; | |
68 | int rc=0, sid=-1, op=OP_NOOP, type=-1, do_logout=0, do_stats=0; | |
69 | int do_login_all=0, do_logout_all=0, info_level=-1, num_ifaces = 0; | |
70 | @@ -2837,6 +2856,12 @@ main(int argc, char **argv) | |
71 | while ((ch = getopt_long(argc, argv, short_options, | |
72 | long_options, &longindex)) >= 0) { | |
73 | switch (ch) { | |
74 | + case 0: | |
75 | + if (long_options[longindex].flag != 0) | |
76 | + break; | |
77 | + if (!strcmp(long_options[longindex].name, "newroot")) | |
78 | + newroot = optarg; | |
79 | + break; | |
80 | case 'k': | |
81 | killiscsid = atoi(optarg); | |
82 | if (killiscsid < 0) { | |
83 | @@ -2989,6 +3014,11 @@ main(int argc, char **argv) | |
84 | goto free_ifaces; | |
85 | } | |
86 | ||
87 | + if (newroot) { | |
88 | + do_newroot(newroot); | |
89 | + goto free_ifaces; | |
90 | + } | |
91 | + | |
92 | if (mode < 0) | |
93 | usage(ISCSI_ERR_INVAL); | |
94 | ||
95 | diff --git a/usr/mgmt_ipc.c b/usr/mgmt_ipc.c | |
96 | index 87bd346..5cb7143 100644 | |
97 | --- a/usr/mgmt_ipc.c | |
98 | +++ b/usr/mgmt_ipc.c | |
99 | @@ -226,6 +226,16 @@ mgmt_ipc_immediate_stop(queue_task_t *qtask) | |
100 | } | |
101 | ||
102 | static int | |
103 | +mgmt_ipc_newroot(queue_task_t *qtask) | |
104 | +{ | |
105 | + char *newroot = qtask->req.u.newroot.path; | |
106 | + if (chdir(newroot) || chroot(".") || chdir("/")) | |
107 | + return ISCSI_ERR; | |
108 | + mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS); | |
109 | + return ISCSI_SUCCESS; | |
110 | +} | |
111 | + | |
112 | +static int | |
113 | mgmt_ipc_conn_remove(queue_task_t *qtask) | |
114 | { | |
115 | return ISCSI_ERR; | |
116 | @@ -534,6 +544,7 @@ static mgmt_ipc_fn_t * mgmt_ipc_functions[__MGMT_IPC_MAX_COMMAND] = { | |
117 | [MGMT_IPC_NOTIFY_DEL_NODE] = mgmt_ipc_notify_del_node, | |
118 | [MGMT_IPC_NOTIFY_ADD_PORTAL] = mgmt_ipc_notify_add_portal, | |
119 | [MGMT_IPC_NOTIFY_DEL_PORTAL] = mgmt_ipc_notify_del_portal, | |
120 | +[MGMT_IPC_NEWROOT] = mgmt_ipc_newroot, | |
121 | }; | |
122 | ||
123 | void mgmt_ipc_handle(int accept_fd) | |
124 | diff --git a/usr/mgmt_ipc.h b/usr/mgmt_ipc.h | |
125 | index 55972ed..102ffff 100644 | |
126 | --- a/usr/mgmt_ipc.h | |
127 | +++ b/usr/mgmt_ipc.h | |
128 | @@ -22,6 +22,7 @@ | |
129 | #include "types.h" | |
130 | #include "iscsi_if.h" | |
131 | #include "config.h" | |
132 | +#include "limits.h" | |
133 | ||
134 | #define ISCSIADM_NAMESPACE "ISCSIADM_ABSTRACT_NAMESPACE" | |
135 | #define PEERUSER_MAX 64 | |
136 | @@ -46,6 +47,7 @@ typedef enum iscsiadm_cmd { | |
137 | MGMT_IPC_NOTIFY_DEL_NODE = 17, | |
138 | MGMT_IPC_NOTIFY_ADD_PORTAL = 18, | |
139 | MGMT_IPC_NOTIFY_DEL_PORTAL = 19, | |
140 | + MGMT_IPC_NEWROOT = 20, | |
141 | ||
142 | __MGMT_IPC_MAX_COMMAND | |
143 | } iscsiadm_cmd_e; | |
144 | @@ -75,8 +77,10 @@ typedef struct iscsiadm_req { | |
145 | int param; | |
146 | /* TODO: make this variable len to support */ | |
147 | char value[IFNAMSIZ + 1]; | |
148 | - | |
149 | } set_host_param; | |
150 | + struct ipc_msg_newroot { | |
151 | + char path[PATH_MAX + 1]; | |
152 | + } newroot; | |
153 | } u; | |
154 | } iscsiadm_req_t; | |
155 | ||
156 | -- | |
157 | 1.8.1.4 | |
158 |