Date: Tue, 22 Sep 2015 10:45:51 +0000 (UTC) From: Alexander Motin <mav@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r288104 - head/sys/cam/ctl Message-ID: <201509221045.t8MAjp0e081942@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mav Date: Tue Sep 22 10:45:50 2015 New Revision: 288104 URL: https://svnweb.freebsd.org/changeset/base/288104 Log: Remove duplicate and incomplete code handling LUN modify. Instead reuse code from LUN creation. This allows most of LUN media options to be changed live with modify request without full restart. Modified: head/sys/cam/ctl/ctl_backend_block.c Modified: head/sys/cam/ctl/ctl_backend_block.c ============================================================================== --- head/sys/cam/ctl/ctl_backend_block.c Tue Sep 22 10:31:48 2015 (r288103) +++ head/sys/cam/ctl/ctl_backend_block.c Tue Sep 22 10:45:50 2015 (r288104) @@ -263,10 +263,6 @@ static int ctl_be_block_create(struct ct struct ctl_lun_req *req); static int ctl_be_block_rm(struct ctl_be_block_softc *softc, struct ctl_lun_req *req); -static int ctl_be_block_modify_file(struct ctl_be_block_lun *be_lun, - struct ctl_lun_req *req); -static int ctl_be_block_modify_dev(struct ctl_be_block_lun *be_lun, - struct ctl_lun_req *req); static int ctl_be_block_modify(struct ctl_be_block_softc *softc, struct ctl_lun_req *req); static void ctl_be_block_lun_shutdown(void *be_lun); @@ -2593,85 +2589,6 @@ bailout_error: } static int -ctl_be_block_modify_file(struct ctl_be_block_lun *be_lun, - struct ctl_lun_req *req) -{ - struct ctl_be_lun *cbe_lun = &be_lun->cbe_lun; - struct vattr vattr; - int error; - struct ctl_lun_create_params *params = &be_lun->params; - - if (params->lun_size_bytes != 0) { - be_lun->size_bytes = params->lun_size_bytes; - } else { - vn_lock(be_lun->vn, LK_SHARED | LK_RETRY); - error = VOP_GETATTR(be_lun->vn, &vattr, curthread->td_ucred); - VOP_UNLOCK(be_lun->vn, 0); - if (error != 0) { - snprintf(req->error_str, sizeof(req->error_str), - "error calling VOP_GETATTR() for file %s", - be_lun->dev_path); - return (error); - } - be_lun->size_bytes = vattr.va_size; - } - be_lun->size_blocks = be_lun->size_bytes / cbe_lun->blocksize; - cbe_lun->maxlba = (be_lun->size_blocks == 0) ? - 0 : (be_lun->size_blocks - 1); - return (0); -} - -static int -ctl_be_block_modify_dev(struct ctl_be_block_lun *be_lun, - struct ctl_lun_req *req) -{ - struct ctl_be_lun *cbe_lun = &be_lun->cbe_lun; - struct ctl_lun_create_params *params = &be_lun->params; - struct cdevsw *csw; - struct cdev *dev; - uint64_t size_bytes; - int error, ref; - - csw = devvn_refthread(be_lun->vn, &dev, &ref); - if (csw == NULL) - return (ENXIO); - if (csw->d_ioctl == NULL) { - dev_relthread(dev, ref); - snprintf(req->error_str, sizeof(req->error_str), - "no d_ioctl for device %s!", be_lun->dev_path); - return (ENODEV); - } - - error = csw->d_ioctl(dev, DIOCGMEDIASIZE, (caddr_t)&size_bytes, FREAD, - curthread); - dev_relthread(dev, ref); - if (error) { - snprintf(req->error_str, sizeof(req->error_str), - "error %d returned for DIOCGMEDIASIZE ioctl " - "on %s!", error, be_lun->dev_path); - return (error); - } - - if (params->lun_size_bytes != 0) { - if (params->lun_size_bytes > size_bytes) { - snprintf(req->error_str, sizeof(req->error_str), - "requested LUN size %ju > backing device " - "size %ju", - (uintmax_t)params->lun_size_bytes, - (uintmax_t)size_bytes); - return (EINVAL); - } - be_lun->size_bytes = params->lun_size_bytes; - } else { - be_lun->size_bytes = size_bytes; - } - be_lun->size_blocks = be_lun->size_bytes / cbe_lun->blocksize; - cbe_lun->maxlba = (be_lun->size_blocks == 0) ? - 0 : (be_lun->size_blocks - 1); - return (0); -} - -static int ctl_be_block_modify(struct ctl_be_block_softc *softc, struct ctl_lun_req *req) { struct ctl_lun_modify_params *params; @@ -2726,9 +2643,9 @@ ctl_be_block_modify(struct ctl_be_block_ if (be_lun->vn == NULL) error = ctl_be_block_open(softc, be_lun, req); else if (vn_isdisk(be_lun->vn, &error)) - error = ctl_be_block_modify_dev(be_lun, req); + error = ctl_be_block_open_dev(be_lun, req); else if (be_lun->vn->v_type == VREG) - error = ctl_be_block_modify_file(be_lun, req); + error = ctl_be_block_open_file(be_lun, req); else error = EINVAL; if ((cbe_lun->flags & CTL_LUN_FLAG_OFFLINE) &&
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201509221045.t8MAjp0e081942>