summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ctladm
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2012-03-06 13:43:57 +0000
committertrasz <trasz@FreeBSD.org>2012-03-06 13:43:57 +0000
commit1d720144fdb563ad9f7045262dffe76fda283e23 (patch)
tree21a7004b7ca48373596470e3a58af3c4b396cd5a /usr.sbin/ctladm
parent1c33114ffdd61c716e728a416a6e816ebcb7f135 (diff)
downloadFreeBSD-src-1d720144fdb563ad9f7045262dffe76fda283e23.zip
FreeBSD-src-1d720144fdb563ad9f7045262dffe76fda283e23.tar.gz
Add LUN resizing to CTL. Also make it possible to explicitly set
size when creating file-backed or device-backed LUN. Reviewed by: ken (earlier version) Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'usr.sbin/ctladm')
-rw-r--r--usr.sbin/ctladm/Makefile4
-rw-r--r--usr.sbin/ctladm/ctladm.828
-rw-r--r--usr.sbin/ctladm/ctladm.c106
3 files changed, 131 insertions, 7 deletions
diff --git a/usr.sbin/ctladm/Makefile b/usr.sbin/ctladm/Makefile
index 88e82f4..4d08f6e 100644
--- a/usr.sbin/ctladm/Makefile
+++ b/usr.sbin/ctladm/Makefile
@@ -14,8 +14,8 @@ CFLAGS+= -I${SDIR}
WARNS?= 3
.endif
-DPADD= ${LIBCAM} ${LIBSBUF}
-LDADD= -lcam -lsbuf -lbsdxml
+DPADD= ${LIBCAM} ${LIBSBUF} ${LIBBSDXML} ${LIBUTIL}
+LDADD= -lcam -lsbuf -lbsdxml -lutil
MAN= ctladm.8
.include <bsd.prog.mk>
diff --git a/usr.sbin/ctladm/ctladm.8 b/usr.sbin/ctladm/ctladm.8
index 027d89e..18333d9 100644
--- a/usr.sbin/ctladm/ctladm.8
+++ b/usr.sbin/ctladm/ctladm.8
@@ -34,7 +34,7 @@
.\" $Id: //depot/users/kenm/FreeBSD-test2/usr.sbin/ctladm/ctladm.8#3 $
.\" $FreeBSD$
.\"
-.Dd July 8, 2011
+.Dd March 6, 2012
.Dt CTLADM 8
.Os
.Sh NAME
@@ -173,6 +173,11 @@
.Aq Fl l Ar lun_id
.Op Fl o Ar name=value
.Nm
+.Ic modify
+.Aq Fl b Ar backend
+.Aq Fl l Ar lun_id
+.Aq Fl s Ar size_bytes
+.Nm
.Ic devlist
.Op Fl b Ar backend
.Op Fl v
@@ -830,6 +835,27 @@ Multiple
arguments may be specified.
Refer to the backend documentation for arguments that may be used.
.El
+.It Ic modify
+Modify a LUN size.
+The backend, the LUN number, and the size must be specified.
+.Bl -tag -width 14n
+.It Fl b Ar backend
+Specify the backend that owns the LUN to be removed.
+Examples are
+.Dq ramdisk
+and
+.Dq block .
+.It Fl l Ar lun_id
+Specify the LUN number to remove.
+.It Fl s Ar size_bytes
+Specify the size of the LUN in bytes.
+For the
+.Dq block
+backend, an
+.Dq auto
+keyword may be passed instead; this will make CTL use the size of backing
+file or device.
+.El
.It Ic devlist
Get a list of all configured LUNs.
This also includes the LUN size and blocksize, serial number and device ID.
diff --git a/usr.sbin/ctladm/ctladm.c b/usr.sbin/ctladm/ctladm.c
index 77e7b02..f53e9f1 100644
--- a/usr.sbin/ctladm/ctladm.c
+++ b/usr.sbin/ctladm/ctladm.c
@@ -1,8 +1,12 @@
/*-
* Copyright (c) 2003, 2004 Silicon Graphics International Corp.
* Copyright (c) 1997-2007 Kenneth D. Merry
+ * Copyright (c) 2012 The FreeBSD Foundation
* All rights reserved.
*
+ * Portions of this software were developed by Edward Tomasz Napierala
+ * under sponsorship from the FreeBSD Foundation.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -68,6 +72,7 @@ __FBSDID("$FreeBSD$");
#include <cam/ctl/ctl_util.h>
#include <cam/ctl/ctl_scsi_all.h>
#include <camlib.h>
+#include <libutil.h>
#include "ctladm.h"
#ifdef min
@@ -110,7 +115,8 @@ typedef enum {
CTLADM_CMD_PRES_IN,
CTLADM_CMD_PRES_OUT,
CTLADM_CMD_INQ_VPD_DEVID,
- CTLADM_CMD_RTPG
+ CTLADM_CMD_RTPG,
+ CTLADM_CMD_MODIFY
} ctladm_cmdfunction;
typedef enum {
@@ -175,6 +181,7 @@ struct ctladm_opts option_table[] = {
{"inquiry", CTLADM_CMD_INQUIRY, CTLADM_ARG_NEED_TL, NULL},
{"lunlist", CTLADM_CMD_LUNLIST, CTLADM_ARG_NONE, NULL},
{"modesense", CTLADM_CMD_MODESENSE, CTLADM_ARG_NEED_TL, "P:S:dlm:c:"},
+ {"modify", CTLADM_CMD_MODIFY, CTLADM_ARG_NONE, "b:l:s:"},
{"port", CTLADM_CMD_PORT, CTLADM_ARG_NONE, "lo:p:qt:w:W:x"},
{"prin", CTLADM_CMD_PRES_IN, CTLADM_ARG_NEED_TL, "a:"},
{"prout", CTLADM_CMD_PRES_OUT, CTLADM_ARG_NEED_TL, "a:k:r:s:"},
@@ -249,6 +256,7 @@ static int cctl_create_lun(int fd, int argc, char **argv, char *combinedopt);
static int cctl_inquiry_vpd_devid(int fd, int target, int lun, int initiator);
static int cctl_report_target_port_group(int fd, int target, int lun,
int initiator);
+static int cctl_modify_lun(int fd, int argc, char **argv, char *combinedopt);
ctladm_optret
getoption(struct ctladm_opts *table, char *arg, uint32_t *cmdnum,
@@ -3045,7 +3053,15 @@ cctl_create_lun(int fd, int argc, char **argv, char *combinedopt)
break;
}
case 's':
- lun_size = strtoull(optarg, NULL, 0);
+ if (strcasecmp(optarg, "auto") != 0) {
+ retval = expand_number(optarg, &lun_size);
+ if (retval != 0) {
+ warn("%s: invalid -s argument",
+ __func__);
+ retval = 1;
+ goto bailout;
+ }
+ }
lun_size_set = 1;
break;
case 'S':
@@ -3289,12 +3305,12 @@ cctl_rm_lun(int fd, int argc, char **argv, char *combinedopt)
}
if (req.status == CTL_LUN_ERROR) {
- warnx("%s: error returned from LUN creation request:\n%s",
+ warnx("%s: error returned from LUN removal request:\n%s",
__func__, req.error_str);
retval = 1;
goto bailout;
} else if (req.status != CTL_LUN_OK) {
- warnx("%s: unknown LUN creation request status %d",
+ warnx("%s: unknown LUN removal request status %d",
__func__, req.status);
retval = 1;
goto bailout;
@@ -3306,6 +3322,84 @@ bailout:
return (retval);
}
+static int
+cctl_modify_lun(int fd, int argc, char **argv, char *combinedopt)
+{
+ struct ctl_lun_req req;
+ uint64_t lun_size = 0;
+ uint32_t lun_id = 0;
+ int lun_id_set = 0, lun_size_set = 0;
+ char *backend_name = NULL;
+ int retval = 0, c;
+
+ while ((c = getopt(argc, argv, combinedopt)) != -1) {
+ switch (c) {
+ case 'b':
+ backend_name = strdup(optarg);
+ break;
+ case 'l':
+ lun_id = strtoul(optarg, NULL, 0);
+ lun_id_set = 1;
+ break;
+ case 's':
+ if (strcasecmp(optarg, "auto") != 0) {
+ retval = expand_number(optarg, &lun_size);
+ if (retval != 0) {
+ warn("%s: invalid -s argument",
+ __func__);
+ retval = 1;
+ goto bailout;
+ }
+ }
+ lun_size_set = 1;
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (backend_name == NULL)
+ errx(1, "%s: backend name (-b) must be specified", __func__);
+
+ if (lun_id_set == 0)
+ errx(1, "%s: LUN id (-l) must be specified", __func__);
+
+ if (lun_size_set == 0)
+ errx(1, "%s: size (-s) must be specified", __func__);
+
+ bzero(&req, sizeof(req));
+
+ strlcpy(req.backend, backend_name, sizeof(req.backend));
+ req.reqtype = CTL_LUNREQ_MODIFY;
+
+ req.reqdata.modify.lun_id = lun_id;
+ req.reqdata.modify.lun_size_bytes = lun_size;
+
+ if (ioctl(fd, CTL_LUN_REQ, &req) == -1) {
+ warn("%s: error issuing CTL_LUN_REQ ioctl", __func__);
+ retval = 1;
+ goto bailout;
+ }
+
+ if (req.status == CTL_LUN_ERROR) {
+ warnx("%s: error returned from LUN modification request:\n%s",
+ __func__, req.error_str);
+ retval = 1;
+ goto bailout;
+ } else if (req.status != CTL_LUN_OK) {
+ warnx("%s: unknown LUN modification request status %d",
+ __func__, req.status);
+ retval = 1;
+ goto bailout;
+ }
+
+ printf("LUN %d modified successfully\n", lun_id);
+
+bailout:
+ return (retval);
+}
+
+
/*
* Name/value pair used for per-LUN attributes.
*/
@@ -3601,6 +3695,7 @@ usage(int error)
" [-l lun_id] [-o name=value] [-s size_bytes]\n"
" [-S serial_num] [-t dev_type]\n"
" ctladm remove <-b backend> <-l lun_id> [-o name=value]\n"
+" ctladm modify <-b backend> <-l lun_id> <-s size_bytes>\n"
" ctladm devlist [-b][-v][-x]\n"
" ctladm shutdown\n"
" ctladm startup\n"
@@ -3987,6 +4082,9 @@ main(int argc, char **argv)
case CTLADM_CMD_RTPG:
retval = cctl_report_target_port_group(fd, target, lun, initid);
break;
+ case CTLADM_CMD_MODIFY:
+ retval = cctl_modify_lun(fd, argc, argv, combinedopt);
+ break;
case CTLADM_CMD_HELP:
default:
usage(retval);
OpenPOWER on IntegriCloud