ctl_backend_ramdisk.c (265642) | ctl_backend_ramdisk.c (268143) |
---|---|
1/*- 2 * Copyright (c) 2003, 2008 Silicon Graphics International Corp. 3 * Copyright (c) 2012 The FreeBSD Foundation 4 * All rights reserved. 5 * 6 * Portions of this software were developed by Edward Tomasz Napierala 7 * under sponsorship from the FreeBSD Foundation. 8 * --- 26 unchanged lines hidden (view full) --- 35 */ 36/* 37 * CAM Target Layer backend for a "fake" ramdisk. 38 * 39 * Author: Ken Merry <ken@FreeBSD.org> 40 */ 41 42#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2003, 2008 Silicon Graphics International Corp. 3 * Copyright (c) 2012 The FreeBSD Foundation 4 * All rights reserved. 5 * 6 * Portions of this software were developed by Edward Tomasz Napierala 7 * under sponsorship from the FreeBSD Foundation. 8 * --- 26 unchanged lines hidden (view full) --- 35 */ 36/* 37 * CAM Target Layer backend for a "fake" ramdisk. 38 * 39 * Author: Ken Merry <ken@FreeBSD.org> 40 */ 41 42#include <sys/cdefs.h> |
43__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_backend_ramdisk.c 265642 2014-05-08 07:10:38Z mav $"); | 43__FBSDID("$FreeBSD: stable/10/sys/cam/ctl/ctl_backend_ramdisk.c 268143 2014-07-02 10:35:06Z mav $"); |
44 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/kernel.h> 48#include <sys/condvar.h> 49#include <sys/types.h> 50#include <sys/lock.h> 51#include <sys/mutex.h> --- 445 unchanged lines hidden (view full) --- 497 softc->num_luns--; 498 } 499 500 mtx_unlock(&softc->lock); 501 502 if (retval == 0) { 503 taskqueue_drain(be_lun->io_taskqueue, &be_lun->io_task); 504 taskqueue_free(be_lun->io_taskqueue); | 44 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/kernel.h> 48#include <sys/condvar.h> 49#include <sys/types.h> 50#include <sys/lock.h> 51#include <sys/mutex.h> --- 445 unchanged lines hidden (view full) --- 497 softc->num_luns--; 498 } 499 500 mtx_unlock(&softc->lock); 501 502 if (retval == 0) { 503 taskqueue_drain(be_lun->io_taskqueue, &be_lun->io_task); 504 taskqueue_free(be_lun->io_taskqueue); |
505 ctl_free_opts(&be_lun->ctl_be_lun); |
|
505 mtx_destroy(&be_lun->lock); 506 free(be_lun, M_RAMDISK); 507 } 508 509 req->status = CTL_LUN_OK; 510 511 return (retval); 512 --- 5 unchanged lines hidden (view full) --- 518 519static int 520ctl_backend_ramdisk_create(struct ctl_be_ramdisk_softc *softc, 521 struct ctl_lun_req *req, int do_wait) 522{ 523 struct ctl_be_ramdisk_lun *be_lun; 524 struct ctl_lun_create_params *params; 525 uint32_t blocksize; | 506 mtx_destroy(&be_lun->lock); 507 free(be_lun, M_RAMDISK); 508 } 509 510 req->status = CTL_LUN_OK; 511 512 return (retval); 513 --- 5 unchanged lines hidden (view full) --- 519 520static int 521ctl_backend_ramdisk_create(struct ctl_be_ramdisk_softc *softc, 522 struct ctl_lun_req *req, int do_wait) 523{ 524 struct ctl_be_ramdisk_lun *be_lun; 525 struct ctl_lun_create_params *params; 526 uint32_t blocksize; |
527 char *value; |
|
526 char tmpstr[32]; | 528 char tmpstr[32]; |
527 int i, retval, unmap; | 529 int retval, unmap; |
528 529 retval = 0; 530 params = &req->reqdata.create; 531 if (params->blocksize_bytes != 0) 532 blocksize = params->blocksize_bytes; 533 else 534 blocksize = 512; 535 536 be_lun = malloc(sizeof(*be_lun), M_RAMDISK, M_ZERO | (do_wait ? 537 M_WAITOK : M_NOWAIT)); 538 539 if (be_lun == NULL) { 540 snprintf(req->error_str, sizeof(req->error_str), 541 "%s: error allocating %zd bytes", __func__, 542 sizeof(*be_lun)); 543 goto bailout_error; 544 } 545 sprintf(be_lun->lunname, "cram%d", softc->num_luns); | 530 531 retval = 0; 532 params = &req->reqdata.create; 533 if (params->blocksize_bytes != 0) 534 blocksize = params->blocksize_bytes; 535 else 536 blocksize = 512; 537 538 be_lun = malloc(sizeof(*be_lun), M_RAMDISK, M_ZERO | (do_wait ? 539 M_WAITOK : M_NOWAIT)); 540 541 if (be_lun == NULL) { 542 snprintf(req->error_str, sizeof(req->error_str), 543 "%s: error allocating %zd bytes", __func__, 544 sizeof(*be_lun)); 545 goto bailout_error; 546 } 547 sprintf(be_lun->lunname, "cram%d", softc->num_luns); |
546 STAILQ_INIT(&be_lun->ctl_be_lun.options); | 548 ctl_init_opts(&be_lun->ctl_be_lun, req); |
547 548 if (params->flags & CTL_LUN_FLAG_DEV_TYPE) 549 be_lun->ctl_be_lun.lun_type = params->device_type; 550 else 551 be_lun->ctl_be_lun.lun_type = T_DIRECT; 552 553 if (be_lun->ctl_be_lun.lun_type == T_DIRECT) { 554 --- 21 unchanged lines hidden (view full) --- 576 params->blocksize_bytes = blocksize; 577 578 /* Tell the user the exact size we ended up using */ 579 params->lun_size_bytes = be_lun->size_bytes; 580 581 be_lun->softc = softc; 582 583 unmap = 0; | 549 550 if (params->flags & CTL_LUN_FLAG_DEV_TYPE) 551 be_lun->ctl_be_lun.lun_type = params->device_type; 552 else 553 be_lun->ctl_be_lun.lun_type = T_DIRECT; 554 555 if (be_lun->ctl_be_lun.lun_type == T_DIRECT) { 556 --- 21 unchanged lines hidden (view full) --- 578 params->blocksize_bytes = blocksize; 579 580 /* Tell the user the exact size we ended up using */ 581 params->lun_size_bytes = be_lun->size_bytes; 582 583 be_lun->softc = softc; 584 585 unmap = 0; |
584 for (i = 0; i < req->num_be_args; i++) { 585 if (strcmp(req->kern_be_args[i].kname, "unmap") == 0 && 586 strcmp(req->kern_be_args[i].kvalue, "on") == 0) { 587 unmap = 1; 588 } else { 589 struct ctl_be_lun_option *opt; | 586 value = ctl_get_opt(&be_lun->ctl_be_lun, "unmap"); 587 if (value != NULL && strcmp(value, "on") == 0) 588 unmap = 1; |
590 | 589 |
591 opt = malloc(sizeof(*opt), M_RAMDISK, M_WAITOK); 592 opt->name = malloc(strlen(req->kern_be_args[i].kname) + 1, M_RAMDISK, M_WAITOK); 593 strcpy(opt->name, req->kern_be_args[i].kname); 594 opt->value = malloc(strlen(req->kern_be_args[i].kvalue) + 1, M_RAMDISK, M_WAITOK); 595 strcpy(opt->value, req->kern_be_args[i].kvalue); 596 STAILQ_INSERT_TAIL(&be_lun->ctl_be_lun.options, opt, links); 597 } 598 } 599 | |
600 be_lun->flags = CTL_BE_RAMDISK_LUN_UNCONFIGURED; 601 be_lun->ctl_be_lun.flags = CTL_LUN_FLAG_PRIMARY; 602 if (unmap) 603 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_UNMAP; 604 be_lun->ctl_be_lun.be_lun = be_lun; 605 606 if (params->flags & CTL_LUN_FLAG_ID_REQ) { 607 be_lun->ctl_be_lun.req_lun_id = params->req_lun_id; --- 115 unchanged lines hidden (view full) --- 723 return (retval); 724 725bailout_error: 726 req->status = CTL_LUN_ERROR; 727 if (be_lun != NULL) { 728 if (be_lun->io_taskqueue != NULL) { 729 taskqueue_free(be_lun->io_taskqueue); 730 } | 590 be_lun->flags = CTL_BE_RAMDISK_LUN_UNCONFIGURED; 591 be_lun->ctl_be_lun.flags = CTL_LUN_FLAG_PRIMARY; 592 if (unmap) 593 be_lun->ctl_be_lun.flags |= CTL_LUN_FLAG_UNMAP; 594 be_lun->ctl_be_lun.be_lun = be_lun; 595 596 if (params->flags & CTL_LUN_FLAG_ID_REQ) { 597 be_lun->ctl_be_lun.req_lun_id = params->req_lun_id; --- 115 unchanged lines hidden (view full) --- 713 return (retval); 714 715bailout_error: 716 req->status = CTL_LUN_ERROR; 717 if (be_lun != NULL) { 718 if (be_lun->io_taskqueue != NULL) { 719 taskqueue_free(be_lun->io_taskqueue); 720 } |
721 ctl_free_opts(&be_lun->ctl_be_lun); |
|
731 mtx_destroy(&be_lun->lock); 732 free(be_lun, M_RAMDISK); 733 } 734 735 return (retval); 736} 737 738static int --- 239 unchanged lines hidden --- | 722 mtx_destroy(&be_lun->lock); 723 free(be_lun, M_RAMDISK); 724 } 725 726 return (retval); 727} 728 729static int --- 239 unchanged lines hidden --- |