Deleted Added
full compact
ctladm.c (287458) ctladm.c (287500)
1/*-
2 * Copyright (c) 2003, 2004 Silicon Graphics International Corp.
3 * Copyright (c) 1997-2007 Kenneth D. Merry
4 * Copyright (c) 2012 The FreeBSD Foundation
5 * All rights reserved.
6 *
7 * Portions of this software were developed by Edward Tomasz Napierala
8 * under sponsorship from the FreeBSD Foundation.

--- 27 unchanged lines hidden (view full) ---

36 */
37/*
38 * CAM Target Layer exercise program.
39 *
40 * Author: Ken Merry <ken@FreeBSD.org>
41 */
42
43#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2003, 2004 Silicon Graphics International Corp.
3 * Copyright (c) 1997-2007 Kenneth D. Merry
4 * Copyright (c) 2012 The FreeBSD Foundation
5 * All rights reserved.
6 *
7 * Portions of this software were developed by Edward Tomasz Napierala
8 * under sponsorship from the FreeBSD Foundation.

--- 27 unchanged lines hidden (view full) ---

36 */
37/*
38 * CAM Target Layer exercise program.
39 *
40 * Author: Ken Merry <ken@FreeBSD.org>
41 */
42
43#include <sys/cdefs.h>
44__FBSDID("$FreeBSD: head/usr.sbin/ctladm/ctladm.c 287458 2015-09-04 10:14:58Z mav $");
44__FBSDID("$FreeBSD: head/usr.sbin/ctladm/ctladm.c 287500 2015-09-06 11:23:01Z mav $");
45
46#include <sys/ioctl.h>
47#include <sys/types.h>
48#include <sys/stat.h>
49#include <sys/param.h>
50#include <sys/linker.h>
51#include <sys/queue.h>
52#include <sys/callout.h>

--- 125 unchanged lines hidden (view full) ---

178 {"inject", CTLADM_CMD_ERR_INJECT, CTLADM_ARG_NEED_TL, "cd:i:p:r:s:"},
179 {"inquiry", CTLADM_CMD_INQUIRY, CTLADM_ARG_NEED_TL, NULL},
180 {"islist", CTLADM_CMD_ISLIST, CTLADM_ARG_NONE, "vx"},
181 {"islogout", CTLADM_CMD_ISLOGOUT, CTLADM_ARG_NONE, "ac:i:p:"},
182 {"isterminate", CTLADM_CMD_ISTERMINATE, CTLADM_ARG_NONE, "ac:i:p:"},
183 {"lunlist", CTLADM_CMD_LUNLIST, CTLADM_ARG_NONE, NULL},
184 {"lunmap", CTLADM_CMD_LUNMAP, CTLADM_ARG_NONE, "p:l:L:"},
185 {"modesense", CTLADM_CMD_MODESENSE, CTLADM_ARG_NEED_TL, "P:S:dlm:c:"},
45
46#include <sys/ioctl.h>
47#include <sys/types.h>
48#include <sys/stat.h>
49#include <sys/param.h>
50#include <sys/linker.h>
51#include <sys/queue.h>
52#include <sys/callout.h>

--- 125 unchanged lines hidden (view full) ---

178 {"inject", CTLADM_CMD_ERR_INJECT, CTLADM_ARG_NEED_TL, "cd:i:p:r:s:"},
179 {"inquiry", CTLADM_CMD_INQUIRY, CTLADM_ARG_NEED_TL, NULL},
180 {"islist", CTLADM_CMD_ISLIST, CTLADM_ARG_NONE, "vx"},
181 {"islogout", CTLADM_CMD_ISLOGOUT, CTLADM_ARG_NONE, "ac:i:p:"},
182 {"isterminate", CTLADM_CMD_ISTERMINATE, CTLADM_ARG_NONE, "ac:i:p:"},
183 {"lunlist", CTLADM_CMD_LUNLIST, CTLADM_ARG_NONE, NULL},
184 {"lunmap", CTLADM_CMD_LUNMAP, CTLADM_ARG_NONE, "p:l:L:"},
185 {"modesense", CTLADM_CMD_MODESENSE, CTLADM_ARG_NEED_TL, "P:S:dlm:c:"},
186 {"modify", CTLADM_CMD_MODIFY, CTLADM_ARG_NONE, "b:l:s:"},
186 {"modify", CTLADM_CMD_MODIFY, CTLADM_ARG_NONE, "b:l:o:s:"},
187 {"port", CTLADM_CMD_PORT, CTLADM_ARG_NONE, "lo:p:qt:w:W:x"},
188 {"portlist", CTLADM_CMD_PORTLIST, CTLADM_ARG_NONE, "f:ilp:qvx"},
189 {"prin", CTLADM_CMD_PRES_IN, CTLADM_ARG_NEED_TL, "a:"},
190 {"prout", CTLADM_CMD_PRES_OUT, CTLADM_ARG_NEED_TL, "a:k:r:s:"},
191 {"read", CTLADM_CMD_READ, CTLADM_ARG_NEED_TL, rw_opts},
192 {"readcapacity", CTLADM_CMD_READCAPACITY, CTLADM_ARG_NEED_TL, "c:"},
193 {"realsync", CTLADM_CMD_REALSYNC, CTLADM_ARG_NONE, NULL},
194 {"remove", CTLADM_CMD_RM, CTLADM_ARG_NONE, "b:l:o:"},

--- 2969 unchanged lines hidden (view full) ---

3164static int
3165cctl_modify_lun(int fd, int argc, char **argv, char *combinedopt)
3166{
3167 struct ctl_lun_req req;
3168 uint64_t lun_size = 0;
3169 uint32_t lun_id = 0;
3170 int lun_id_set = 0, lun_size_set = 0;
3171 char *backend_name = NULL;
187 {"port", CTLADM_CMD_PORT, CTLADM_ARG_NONE, "lo:p:qt:w:W:x"},
188 {"portlist", CTLADM_CMD_PORTLIST, CTLADM_ARG_NONE, "f:ilp:qvx"},
189 {"prin", CTLADM_CMD_PRES_IN, CTLADM_ARG_NEED_TL, "a:"},
190 {"prout", CTLADM_CMD_PRES_OUT, CTLADM_ARG_NEED_TL, "a:k:r:s:"},
191 {"read", CTLADM_CMD_READ, CTLADM_ARG_NEED_TL, rw_opts},
192 {"readcapacity", CTLADM_CMD_READCAPACITY, CTLADM_ARG_NEED_TL, "c:"},
193 {"realsync", CTLADM_CMD_REALSYNC, CTLADM_ARG_NONE, NULL},
194 {"remove", CTLADM_CMD_RM, CTLADM_ARG_NONE, "b:l:o:"},

--- 2969 unchanged lines hidden (view full) ---

3164static int
3165cctl_modify_lun(int fd, int argc, char **argv, char *combinedopt)
3166{
3167 struct ctl_lun_req req;
3168 uint64_t lun_size = 0;
3169 uint32_t lun_id = 0;
3170 int lun_id_set = 0, lun_size_set = 0;
3171 char *backend_name = NULL;
3172 STAILQ_HEAD(, cctl_req_option) option_list;
3173 int num_options = 0;
3172 int retval = 0, c;
3173
3174 int retval = 0, c;
3175
3176 STAILQ_INIT(&option_list);
3174 while ((c = getopt(argc, argv, combinedopt)) != -1) {
3175 switch (c) {
3176 case 'b':
3177 backend_name = strdup(optarg);
3178 break;
3179 case 'l':
3180 lun_id = strtoul(optarg, NULL, 0);
3181 lun_id_set = 1;
3182 break;
3177 while ((c = getopt(argc, argv, combinedopt)) != -1) {
3178 switch (c) {
3179 case 'b':
3180 backend_name = strdup(optarg);
3181 break;
3182 case 'l':
3183 lun_id = strtoul(optarg, NULL, 0);
3184 lun_id_set = 1;
3185 break;
3186 case 'o': {
3187 struct cctl_req_option *option;
3188 char *tmpstr;
3189 char *name, *value;
3190
3191 tmpstr = strdup(optarg);
3192 name = strsep(&tmpstr, "=");
3193 if (name == NULL) {
3194 warnx("%s: option -o takes \"name=value\""
3195 "argument", __func__);
3196 retval = 1;
3197 goto bailout;
3198 }
3199 value = strsep(&tmpstr, "=");
3200 if (value == NULL) {
3201 warnx("%s: option -o takes \"name=value\""
3202 "argument", __func__);
3203 retval = 1;
3204 goto bailout;
3205 }
3206 option = malloc(sizeof(*option));
3207 if (option == NULL) {
3208 warn("%s: error allocating %zd bytes",
3209 __func__, sizeof(*option));
3210 retval = 1;
3211 goto bailout;
3212 }
3213 option->name = strdup(name);
3214 option->namelen = strlen(name) + 1;
3215 option->value = strdup(value);
3216 option->vallen = strlen(value) + 1;
3217 free(tmpstr);
3218
3219 STAILQ_INSERT_TAIL(&option_list, option, links);
3220 num_options++;
3221 break;
3222 }
3183 case 's':
3184 if (strcasecmp(optarg, "auto") != 0) {
3185 retval = expand_number(optarg, &lun_size);
3186 if (retval != 0) {
3187 warn("%s: invalid -s argument",
3188 __func__);
3189 retval = 1;
3190 goto bailout;

--- 7 unchanged lines hidden (view full) ---

3198 }
3199
3200 if (backend_name == NULL)
3201 errx(1, "%s: backend name (-b) must be specified", __func__);
3202
3203 if (lun_id_set == 0)
3204 errx(1, "%s: LUN id (-l) must be specified", __func__);
3205
3223 case 's':
3224 if (strcasecmp(optarg, "auto") != 0) {
3225 retval = expand_number(optarg, &lun_size);
3226 if (retval != 0) {
3227 warn("%s: invalid -s argument",
3228 __func__);
3229 retval = 1;
3230 goto bailout;

--- 7 unchanged lines hidden (view full) ---

3238 }
3239
3240 if (backend_name == NULL)
3241 errx(1, "%s: backend name (-b) must be specified", __func__);
3242
3243 if (lun_id_set == 0)
3244 errx(1, "%s: LUN id (-l) must be specified", __func__);
3245
3206 if (lun_size_set == 0)
3207 errx(1, "%s: size (-s) must be specified", __func__);
3246 if (lun_size_set == 0 && num_options == 0)
3247 errx(1, "%s: size (-s) or options (-o) must be specified",
3248 __func__);
3208
3209 bzero(&req, sizeof(req));
3210
3211 strlcpy(req.backend, backend_name, sizeof(req.backend));
3212 req.reqtype = CTL_LUNREQ_MODIFY;
3213
3214 req.reqdata.modify.lun_id = lun_id;
3215 req.reqdata.modify.lun_size_bytes = lun_size;
3216
3249
3250 bzero(&req, sizeof(req));
3251
3252 strlcpy(req.backend, backend_name, sizeof(req.backend));
3253 req.reqtype = CTL_LUNREQ_MODIFY;
3254
3255 req.reqdata.modify.lun_id = lun_id;
3256 req.reqdata.modify.lun_size_bytes = lun_size;
3257
3258 req.num_be_args = num_options;
3259 if (num_options > 0) {
3260 struct cctl_req_option *option, *next_option;
3261 int i;
3262
3263 req.be_args = malloc(num_options * sizeof(*req.be_args));
3264 if (req.be_args == NULL) {
3265 warn("%s: error allocating %zd bytes", __func__,
3266 num_options * sizeof(*req.be_args));
3267 retval = 1;
3268 goto bailout;
3269 }
3270
3271 for (i = 0, option = STAILQ_FIRST(&option_list);
3272 i < num_options; i++, option = next_option) {
3273 next_option = STAILQ_NEXT(option, links);
3274
3275 req.be_args[i].namelen = option->namelen;
3276 req.be_args[i].name = strdup(option->name);
3277 req.be_args[i].vallen = option->vallen;
3278 req.be_args[i].value = strdup(option->value);
3279 /*
3280 * XXX KDM do we want a way to specify a writeable
3281 * flag of some sort? Do we want a way to specify
3282 * binary data?
3283 */
3284 req.be_args[i].flags = CTL_BEARG_ASCII | CTL_BEARG_RD;
3285
3286 STAILQ_REMOVE(&option_list, option, cctl_req_option,
3287 links);
3288 free(option->name);
3289 free(option->value);
3290 free(option);
3291 }
3292 }
3293
3217 if (ioctl(fd, CTL_LUN_REQ, &req) == -1) {
3218 warn("%s: error issuing CTL_LUN_REQ ioctl", __func__);
3219 retval = 1;
3220 goto bailout;
3221 }
3222
3223 switch (req.status) {
3224 case CTL_LUN_ERROR:

--- 1517 unchanged lines hidden ---
3294 if (ioctl(fd, CTL_LUN_REQ, &req) == -1) {
3295 warn("%s: error issuing CTL_LUN_REQ ioctl", __func__);
3296 retval = 1;
3297 goto bailout;
3298 }
3299
3300 switch (req.status) {
3301 case CTL_LUN_ERROR:

--- 1517 unchanged lines hidden ---