primary.c (214274) | primary.c (214284) |
---|---|
1/*- 2 * Copyright (c) 2009 The FreeBSD Foundation 3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org> 4 * All rights reserved. 5 * 6 * This software was developed by Pawel Jakub Dawidek under sponsorship from 7 * the FreeBSD Foundation. 8 * --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2009 The FreeBSD Foundation 3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org> 4 * All rights reserved. 5 * 6 * This software was developed by Pawel Jakub Dawidek under sponsorship from 7 * the FreeBSD Foundation. 8 * --- 15 unchanged lines hidden (view full) --- 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/sbin/hastd/primary.c 214274 2010-10-24 15:41:23Z pjd $"); | 32__FBSDID("$FreeBSD: head/sbin/hastd/primary.c 214284 2010-10-24 17:28:25Z pjd $"); |
33 34#include <sys/types.h> 35#include <sys/time.h> 36#include <sys/bio.h> 37#include <sys/disk.h> 38#include <sys/refcount.h> 39#include <sys/stat.h> 40 --- 371 unchanged lines hidden (view full) --- 412 MAXPHYS); 413 } 414 hio->hio_ggio.gctl_length = MAXPHYS; 415 hio->hio_ggio.gctl_error = 0; 416 TAILQ_INSERT_HEAD(&hio_free_list, hio, hio_free_next); 417 } 418} 419 | 33 34#include <sys/types.h> 35#include <sys/time.h> 36#include <sys/bio.h> 37#include <sys/disk.h> 38#include <sys/refcount.h> 39#include <sys/stat.h> 40 --- 371 unchanged lines hidden (view full) --- 412 MAXPHYS); 413 } 414 hio->hio_ggio.gctl_length = MAXPHYS; 415 hio->hio_ggio.gctl_error = 0; 416 TAILQ_INSERT_HEAD(&hio_free_list, hio, hio_free_next); 417 } 418} 419 |
420static bool 421init_resuid(struct hast_resource *res) 422{ 423 424 mtx_lock(&metadata_lock); 425 if (res->hr_resuid != 0) { 426 mtx_unlock(&metadata_lock); 427 return (false); 428 } else { 429 /* Initialize unique resource identifier. */ 430 arc4random_buf(&res->hr_resuid, sizeof(res->hr_resuid)); 431 mtx_unlock(&metadata_lock); 432 if (metadata_write(res) < 0) 433 exit(EX_NOINPUT); 434 return (true); 435 } 436} 437 |
|
420static void 421init_local(struct hast_resource *res) 422{ 423 unsigned char *buf; 424 size_t mapsize; 425 426 if (metadata_read(res, true) < 0) 427 exit(EX_NOINPUT); --- 19 unchanged lines hidden (view full) --- 447 (ssize_t)mapsize) { 448 primary_exit(EX_NOINPUT, "Unable to read activemap"); 449 } 450 activemap_copyin(res->hr_amp, buf, mapsize); 451 free(buf); 452 if (res->hr_resuid != 0) 453 return; 454 /* | 438static void 439init_local(struct hast_resource *res) 440{ 441 unsigned char *buf; 442 size_t mapsize; 443 444 if (metadata_read(res, true) < 0) 445 exit(EX_NOINPUT); --- 19 unchanged lines hidden (view full) --- 465 (ssize_t)mapsize) { 466 primary_exit(EX_NOINPUT, "Unable to read activemap"); 467 } 468 activemap_copyin(res->hr_amp, buf, mapsize); 469 free(buf); 470 if (res->hr_resuid != 0) 471 return; 472 /* |
455 * We're using provider for the first time, so we have to generate 456 * resource unique identifier and initialize local and remote counts. | 473 * We're using provider for the first time. Initialize local and remote 474 * counters. We don't initialize resuid here, as we want to do it just 475 * in time. The reason for this is that we want to inform secondary 476 * that there were no writes yet, so there is no need to synchronize 477 * anything. |
457 */ | 478 */ |
458 arc4random_buf(&res->hr_resuid, sizeof(res->hr_resuid)); | |
459 res->hr_primary_localcnt = 1; 460 res->hr_primary_remotecnt = 0; 461 if (metadata_write(res) < 0) 462 exit(EX_NOINPUT); 463} 464 465static bool 466init_remote(struct hast_resource *res, struct proto_conn **inp, --- 94 unchanged lines hidden (view full) --- 561 } 562 /* Error in setting timeout is not critical, but why should it fail? */ 563 if (proto_timeout(in, res->hr_timeout) < 0) 564 pjdlog_errno(LOG_WARNING, "Unable to set connection timeout"); 565 nvout = nv_alloc(); 566 nv_add_string(nvout, res->hr_name, "resource"); 567 nv_add_uint8_array(nvout, res->hr_token, sizeof(res->hr_token), 568 "token"); | 479 res->hr_primary_localcnt = 1; 480 res->hr_primary_remotecnt = 0; 481 if (metadata_write(res) < 0) 482 exit(EX_NOINPUT); 483} 484 485static bool 486init_remote(struct hast_resource *res, struct proto_conn **inp, --- 94 unchanged lines hidden (view full) --- 581 } 582 /* Error in setting timeout is not critical, but why should it fail? */ 583 if (proto_timeout(in, res->hr_timeout) < 0) 584 pjdlog_errno(LOG_WARNING, "Unable to set connection timeout"); 585 nvout = nv_alloc(); 586 nv_add_string(nvout, res->hr_name, "resource"); 587 nv_add_uint8_array(nvout, res->hr_token, sizeof(res->hr_token), 588 "token"); |
589 if (res->hr_resuid == 0) { 590 /* 591 * The resuid field was not yet initialized. 592 * Because we do synchronization inside init_resuid(), it is 593 * possible that someone already initialized it, the function 594 * will return false then, but if we successfully initialized 595 * it, we will get true. True means that there were no writes 596 * to this resource yet and we want to inform secondary that 597 * synchronization is not needed by sending "virgin" argument. 598 */ 599 if (init_resuid(res)) 600 nv_add_int8(nvout, 1, "virgin"); 601 } |
|
569 nv_add_uint64(nvout, res->hr_resuid, "resuid"); 570 nv_add_uint64(nvout, res->hr_primary_localcnt, "localcnt"); 571 nv_add_uint64(nvout, res->hr_primary_remotecnt, "remotecnt"); 572 if (nv_error(nvout) != 0) { 573 pjdlog_common(LOG_WARNING, 0, nv_error(nvout), 574 "Unable to allocate header for connection with %s", 575 res->hr_remoteaddr); 576 nv_free(nvout); --- 424 unchanged lines hidden (view full) --- 1001 */ 1002 /* Remote component is 1 for now. */ 1003 ncomp = 1; 1004 } 1005 mtx_unlock(&metadata_lock); 1006 QUEUE_INSERT1(hio, send, ncomp); 1007 break; 1008 case BIO_WRITE: | 602 nv_add_uint64(nvout, res->hr_resuid, "resuid"); 603 nv_add_uint64(nvout, res->hr_primary_localcnt, "localcnt"); 604 nv_add_uint64(nvout, res->hr_primary_remotecnt, "remotecnt"); 605 if (nv_error(nvout) != 0) { 606 pjdlog_common(LOG_WARNING, 0, nv_error(nvout), 607 "Unable to allocate header for connection with %s", 608 res->hr_remoteaddr); 609 nv_free(nvout); --- 424 unchanged lines hidden (view full) --- 1034 */ 1035 /* Remote component is 1 for now. */ 1036 ncomp = 1; 1037 } 1038 mtx_unlock(&metadata_lock); 1039 QUEUE_INSERT1(hio, send, ncomp); 1040 break; 1041 case BIO_WRITE: |
1042 if (res->hr_resuid == 0) { 1043 /* This is first write, initialize resuid. */ 1044 (void)init_resuid(res); 1045 } |
|
1009 for (;;) { 1010 mtx_lock(&range_lock); 1011 if (rangelock_islocked(range_sync, 1012 ggio->gctl_offset, ggio->gctl_length)) { 1013 pjdlog_debug(2, 1014 "regular: Range offset=%jd length=%zu locked.", 1015 (intmax_t)ggio->gctl_offset, 1016 (size_t)ggio->gctl_length); --- 971 unchanged lines hidden --- | 1046 for (;;) { 1047 mtx_lock(&range_lock); 1048 if (rangelock_islocked(range_sync, 1049 ggio->gctl_offset, ggio->gctl_length)) { 1050 pjdlog_debug(2, 1051 "regular: Range offset=%jd length=%zu locked.", 1052 (intmax_t)ggio->gctl_offset, 1053 (size_t)ggio->gctl_length); --- 971 unchanged lines hidden --- |