secondary.c (229945) | secondary.c (230092) |
---|---|
1/*- 2 * Copyright (c) 2009-2010 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-2010 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/secondary.c 229945 2012-01-10 22:39:07Z pjd $"); | 32__FBSDID("$FreeBSD: head/sbin/hastd/secondary.c 230092 2012-01-13 23:25:35Z pjd $"); |
33 34#include <sys/param.h> 35#include <sys/time.h> 36#include <sys/bio.h> 37#include <sys/disk.h> 38#include <sys/stat.h> 39 40#include <err.h> --- 236 unchanged lines hidden (view full) --- 277 char errmsg[256]; 278 279 free(map); 280 (void)snprintf(errmsg, sizeof(errmsg), 281 "Resource unique ID mismatch (primary=%ju, secondary=%ju).", 282 (uintmax_t)resuid, (uintmax_t)res->hr_resuid); 283 pjdlog_error("%s", errmsg); 284 nv_add_string(nvout, errmsg, "errmsg"); | 33 34#include <sys/param.h> 35#include <sys/time.h> 36#include <sys/bio.h> 37#include <sys/disk.h> 38#include <sys/stat.h> 39 40#include <err.h> --- 236 unchanged lines hidden (view full) --- 277 char errmsg[256]; 278 279 free(map); 280 (void)snprintf(errmsg, sizeof(errmsg), 281 "Resource unique ID mismatch (primary=%ju, secondary=%ju).", 282 (uintmax_t)resuid, (uintmax_t)res->hr_resuid); 283 pjdlog_error("%s", errmsg); 284 nv_add_string(nvout, errmsg, "errmsg"); |
285 if (hast_proto_send(res, res->hr_remotein, nvout, NULL, 0) == -1) { 286 pjdlog_exit(EX_TEMPFAIL, "Unable to send response to %s", | 285 if (hast_proto_send(res, res->hr_remotein, nvout, 286 NULL, 0) == -1) { 287 pjdlog_exit(EX_TEMPFAIL, 288 "Unable to send response to %s", |
287 res->hr_remoteaddr); 288 } 289 nv_free(nvout); 290 exit(EX_CONFIG); 291 } else if ( 292 /* Is primary out-of-date? */ 293 (res->hr_secondary_localcnt > res->hr_primary_remotecnt && 294 res->hr_secondary_remotecnt == res->hr_primary_localcnt) || --- 27 unchanged lines hidden (view full) --- 322 } else if (res->hr_secondary_localcnt > res->hr_primary_remotecnt && 323 res->hr_primary_localcnt > res->hr_secondary_remotecnt) { 324 /* 325 * Not good, we have split-brain condition. 326 */ 327 free(map); 328 pjdlog_error("Split-brain detected, exiting."); 329 nv_add_string(nvout, "Split-brain condition!", "errmsg"); | 289 res->hr_remoteaddr); 290 } 291 nv_free(nvout); 292 exit(EX_CONFIG); 293 } else if ( 294 /* Is primary out-of-date? */ 295 (res->hr_secondary_localcnt > res->hr_primary_remotecnt && 296 res->hr_secondary_remotecnt == res->hr_primary_localcnt) || --- 27 unchanged lines hidden (view full) --- 324 } else if (res->hr_secondary_localcnt > res->hr_primary_remotecnt && 325 res->hr_primary_localcnt > res->hr_secondary_remotecnt) { 326 /* 327 * Not good, we have split-brain condition. 328 */ 329 free(map); 330 pjdlog_error("Split-brain detected, exiting."); 331 nv_add_string(nvout, "Split-brain condition!", "errmsg"); |
330 if (hast_proto_send(res, res->hr_remotein, nvout, NULL, 0) == -1) { 331 pjdlog_exit(EX_TEMPFAIL, "Unable to send response to %s", | 332 if (hast_proto_send(res, res->hr_remotein, nvout, 333 NULL, 0) == -1) { 334 pjdlog_exit(EX_TEMPFAIL, 335 "Unable to send response to %s", |
332 res->hr_remoteaddr); 333 } 334 nv_free(nvout); 335 /* Exit on split-brain. */ 336 event_send(res, EVENT_SPLITBRAIN); 337 exit(EX_CONFIG); 338 } else /* if (res->hr_secondary_localcnt < res->hr_primary_remotecnt || 339 res->hr_primary_localcnt < res->hr_secondary_remotecnt) */ { --- 130 unchanged lines hidden (view full) --- 470 error = pthread_create(&td, NULL, recv_thread, res); 471 PJDLOG_ASSERT(error == 0); 472 error = pthread_create(&td, NULL, disk_thread, res); 473 PJDLOG_ASSERT(error == 0); 474 (void)send_thread(res); 475} 476 477static void | 336 res->hr_remoteaddr); 337 } 338 nv_free(nvout); 339 /* Exit on split-brain. */ 340 event_send(res, EVENT_SPLITBRAIN); 341 exit(EX_CONFIG); 342 } else /* if (res->hr_secondary_localcnt < res->hr_primary_remotecnt || 343 res->hr_primary_localcnt < res->hr_secondary_remotecnt) */ { --- 130 unchanged lines hidden (view full) --- 474 error = pthread_create(&td, NULL, recv_thread, res); 475 PJDLOG_ASSERT(error == 0); 476 error = pthread_create(&td, NULL, disk_thread, res); 477 PJDLOG_ASSERT(error == 0); 478 (void)send_thread(res); 479} 480 481static void |
478reqlog(int loglevel, int debuglevel, int error, struct hio *hio, const char *fmt, ...) | 482reqlog(int loglevel, int debuglevel, int error, struct hio *hio, 483 const char *fmt, ...) |
479{ 480 char msg[1024]; 481 va_list ap; 482 int len; 483 484 va_start(ap, fmt); 485 len = vsnprintf(msg, sizeof(msg), fmt, ap); 486 va_end(ap); --- 346 unchanged lines hidden (view full) --- 833 default: 834 PJDLOG_ABORT("Unexpected command (cmd=%hhu).", 835 hio->hio_cmd); 836 } 837 if (hio->hio_error != 0) 838 nv_add_int16(nvout, hio->hio_error, "error"); 839 if (hast_proto_send(res, res->hr_remoteout, nvout, data, 840 length) == -1) { | 484{ 485 char msg[1024]; 486 va_list ap; 487 int len; 488 489 va_start(ap, fmt); 490 len = vsnprintf(msg, sizeof(msg), fmt, ap); 491 va_end(ap); --- 346 unchanged lines hidden (view full) --- 838 default: 839 PJDLOG_ABORT("Unexpected command (cmd=%hhu).", 840 hio->hio_cmd); 841 } 842 if (hio->hio_error != 0) 843 nv_add_int16(nvout, hio->hio_error, "error"); 844 if (hast_proto_send(res, res->hr_remoteout, nvout, data, 845 length) == -1) { |
841 secondary_exit(EX_TEMPFAIL, "Unable to send reply."); | 846 secondary_exit(EX_TEMPFAIL, "Unable to send reply"); |
842 } 843 nv_free(nvout); 844 pjdlog_debug(2, "send: (%p) Moving request to the free queue.", 845 hio); 846 hio_clear(hio); 847 QUEUE_INSERT(free, hio); 848 } 849 /* NOTREACHED */ 850 return (NULL); 851} | 847 } 848 nv_free(nvout); 849 pjdlog_debug(2, "send: (%p) Moving request to the free queue.", 850 hio); 851 hio_clear(hio); 852 QUEUE_INSERT(free, hio); 853 } 854 /* NOTREACHED */ 855 return (NULL); 856} |