hastctl.c (225785) | hastctl.c (229945) |
---|---|
1/*- 2 * Copyright (c) 2009-2010 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Pawel Jakub Dawidek under sponsorship from 6 * the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2009-2010 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Pawel Jakub Dawidek under sponsorship from 6 * the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sbin/hastctl/hastctl.c 225785 2011-09-27 08:21:00Z pjd $"); | 31__FBSDID("$FreeBSD: head/sbin/hastctl/hastctl.c 229945 2012-01-10 22:39:07Z pjd $"); |
32 33#include <sys/param.h> 34#include <sys/disk.h> 35#include <sys/ioctl.h> 36#include <sys/stat.h> 37#include <sys/sysctl.h> 38 39#include <err.h> --- 59 unchanged lines hidden (view full) --- 99{ 100 unsigned char *buf; 101 size_t mapsize; 102 int ec; 103 104 ec = 0; 105 pjdlog_prefix_set("[%s] ", res->hr_name); 106 | 32 33#include <sys/param.h> 34#include <sys/disk.h> 35#include <sys/ioctl.h> 36#include <sys/stat.h> 37#include <sys/sysctl.h> 38 39#include <err.h> --- 59 unchanged lines hidden (view full) --- 99{ 100 unsigned char *buf; 101 size_t mapsize; 102 int ec; 103 104 ec = 0; 105 pjdlog_prefix_set("[%s] ", res->hr_name); 106 |
107 if (provinfo(res, true) < 0) { | 107 if (provinfo(res, true) == -1) { |
108 ec = EX_NOINPUT; 109 goto end; 110 } 111 if (mediasize == 0) 112 mediasize = res->hr_local_mediasize; 113 else if (mediasize > res->hr_local_mediasize) { 114 pjdlog_error("Provided mediasize is larger than provider %s size.", 115 res->hr_localpath); --- 25 unchanged lines hidden (view full) --- 141 if (keepdirty == 0) 142 keepdirty = HAST_KEEPDIRTY; 143 res->hr_datasize = mediasize - METADATA_SIZE - mapsize; 144 res->hr_extentsize = extentsize; 145 res->hr_keepdirty = keepdirty; 146 147 res->hr_localoff = METADATA_SIZE + mapsize; 148 | 108 ec = EX_NOINPUT; 109 goto end; 110 } 111 if (mediasize == 0) 112 mediasize = res->hr_local_mediasize; 113 else if (mediasize > res->hr_local_mediasize) { 114 pjdlog_error("Provided mediasize is larger than provider %s size.", 115 res->hr_localpath); --- 25 unchanged lines hidden (view full) --- 141 if (keepdirty == 0) 142 keepdirty = HAST_KEEPDIRTY; 143 res->hr_datasize = mediasize - METADATA_SIZE - mapsize; 144 res->hr_extentsize = extentsize; 145 res->hr_keepdirty = keepdirty; 146 147 res->hr_localoff = METADATA_SIZE + mapsize; 148 |
149 if (metadata_write(res) < 0) { | 149 if (metadata_write(res) == -1) { |
150 ec = EX_IOERR; 151 goto end; 152 } 153 buf = calloc(1, mapsize); 154 if (buf == NULL) { 155 pjdlog_error("Unable to allocate %zu bytes of memory for initial bitmap.", 156 mapsize); 157 ec = EX_TEMPFAIL; --- 238 unchanged lines hidden (view full) --- 396 switch (ch) { 397 case 'c': 398 cfgpath = optarg; 399 break; 400 case 'd': 401 debug++; 402 break; 403 case 'e': | 150 ec = EX_IOERR; 151 goto end; 152 } 153 buf = calloc(1, mapsize); 154 if (buf == NULL) { 155 pjdlog_error("Unable to allocate %zu bytes of memory for initial bitmap.", 156 mapsize); 157 ec = EX_TEMPFAIL; --- 238 unchanged lines hidden (view full) --- 396 switch (ch) { 397 case 'c': 398 cfgpath = optarg; 399 break; 400 case 'd': 401 debug++; 402 break; 403 case 'e': |
404 if (expand_number(optarg, &extentsize) < 0) | 404 if (expand_number(optarg, &extentsize) == -1) |
405 errx(EX_USAGE, "Invalid extentsize"); 406 break; 407 case 'k': | 405 errx(EX_USAGE, "Invalid extentsize"); 406 break; 407 case 'k': |
408 if (expand_number(optarg, &keepdirty) < 0) | 408 if (expand_number(optarg, &keepdirty) == -1) |
409 errx(EX_USAGE, "Invalid keepdirty"); 410 break; 411 case 'm': | 409 errx(EX_USAGE, "Invalid keepdirty"); 410 break; 411 case 'm': |
412 if (expand_number(optarg, &mediasize) < 0) | 412 if (expand_number(optarg, &mediasize) == -1) |
413 errx(EX_USAGE, "Invalid mediasize"); 414 break; 415 case 'h': 416 default: 417 usage(); 418 } 419 } 420 argc -= optind; --- 53 unchanged lines hidden (view full) --- 474 nv_add_string(nv, argv[ii], "resource%d", ii); 475 } 476 break; 477 default: 478 PJDLOG_ABORT("Impossible command!"); 479 } 480 481 /* Setup control connection... */ | 413 errx(EX_USAGE, "Invalid mediasize"); 414 break; 415 case 'h': 416 default: 417 usage(); 418 } 419 } 420 argc -= optind; --- 53 unchanged lines hidden (view full) --- 474 nv_add_string(nv, argv[ii], "resource%d", ii); 475 } 476 break; 477 default: 478 PJDLOG_ABORT("Impossible command!"); 479 } 480 481 /* Setup control connection... */ |
482 if (proto_client(NULL, cfg->hc_controladdr, &controlconn) < 0) { | 482 if (proto_client(NULL, cfg->hc_controladdr, &controlconn) == -1) { |
483 pjdlog_exit(EX_OSERR, 484 "Unable to setup control connection to %s", 485 cfg->hc_controladdr); 486 } 487 /* ...and connect to hastd. */ | 483 pjdlog_exit(EX_OSERR, 484 "Unable to setup control connection to %s", 485 cfg->hc_controladdr); 486 } 487 /* ...and connect to hastd. */ |
488 if (proto_connect(controlconn, HAST_TIMEOUT) < 0) { | 488 if (proto_connect(controlconn, HAST_TIMEOUT) == -1) { |
489 pjdlog_exit(EX_OSERR, "Unable to connect to hastd via %s", 490 cfg->hc_controladdr); 491 } 492 493 if (drop_privs(NULL) != 0) 494 exit(EX_CONFIG); 495 496 /* Send the command to the server... */ | 489 pjdlog_exit(EX_OSERR, "Unable to connect to hastd via %s", 490 cfg->hc_controladdr); 491 } 492 493 if (drop_privs(NULL) != 0) 494 exit(EX_CONFIG); 495 496 /* Send the command to the server... */ |
497 if (hast_proto_send(NULL, controlconn, nv, NULL, 0) < 0) { | 497 if (hast_proto_send(NULL, controlconn, nv, NULL, 0) == -1) { |
498 pjdlog_exit(EX_UNAVAILABLE, 499 "Unable to send command to hastd via %s", 500 cfg->hc_controladdr); 501 } 502 nv_free(nv); 503 /* ...and receive reply. */ | 498 pjdlog_exit(EX_UNAVAILABLE, 499 "Unable to send command to hastd via %s", 500 cfg->hc_controladdr); 501 } 502 nv_free(nv); 503 /* ...and receive reply. */ |
504 if (hast_proto_recv_hdr(controlconn, &nv) < 0) { | 504 if (hast_proto_recv_hdr(controlconn, &nv) == -1) { |
505 pjdlog_exit(EX_UNAVAILABLE, 506 "cannot receive reply from hastd via %s", 507 cfg->hc_controladdr); 508 } 509 510 error = nv_get_int16(nv, "error"); 511 if (error != 0) { 512 pjdlog_exitx(EX_SOFTWARE, "Error %d received from hastd.", --- 17 unchanged lines hidden --- | 505 pjdlog_exit(EX_UNAVAILABLE, 506 "cannot receive reply from hastd via %s", 507 cfg->hc_controladdr); 508 } 509 510 error = nv_get_int16(nv, "error"); 511 if (error != 0) { 512 pjdlog_exitx(EX_SOFTWARE, "Error %d received from hastd.", --- 17 unchanged lines hidden --- |