Deleted Added
full compact
primary.c (255714) primary.c (255716)
1/*-
2 * Copyright (c) 2009 The FreeBSD Foundation
3 * Copyright (c) 2010-2011 Pawel Jakub Dawidek <pawel@dawidek.net>
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-2011 Pawel Jakub Dawidek <pawel@dawidek.net>
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 255714 2013-09-19 20:15:24Z trociny $");
32__FBSDID("$FreeBSD: head/sbin/hastd/primary.c 255716 2013-09-19 20:19:08Z trociny $");
33
34#include <sys/types.h>
35#include <sys/time.h>
36#include <sys/bio.h>
37#include <sys/disk.h>
38#include <sys/stat.h>
39
40#include <geom/gate/g_gate.h>

--- 245 unchanged lines hidden (view full) ---

286
287 va_start(ap, fmt);
288 pjdlogv(exitcode == EX_OK ? LOG_INFO : LOG_ERR, fmt, ap);
289 va_end(ap);
290 cleanup(gres);
291 exit(exitcode);
292}
293
33
34#include <sys/types.h>
35#include <sys/time.h>
36#include <sys/bio.h>
37#include <sys/disk.h>
38#include <sys/stat.h>
39
40#include <geom/gate/g_gate.h>

--- 245 unchanged lines hidden (view full) ---

286
287 va_start(ap, fmt);
288 pjdlogv(exitcode == EX_OK ? LOG_INFO : LOG_ERR, fmt, ap);
289 va_end(ap);
290 cleanup(gres);
291 exit(exitcode);
292}
293
294/* Expects res->hr_amp locked, returns unlocked. */
294static int
295hast_activemap_flush(struct hast_resource *res)
296{
297 const unsigned char *buf;
298 size_t size;
295static int
296hast_activemap_flush(struct hast_resource *res)
297{
298 const unsigned char *buf;
299 size_t size;
300 int ret;
299
301
302 mtx_lock(&res->hr_amp_diskmap_lock);
300 buf = activemap_bitmap(res->hr_amp, &size);
303 buf = activemap_bitmap(res->hr_amp, &size);
304 mtx_unlock(&res->hr_amp_lock);
301 PJDLOG_ASSERT(buf != NULL);
302 PJDLOG_ASSERT((size % res->hr_local_sectorsize) == 0);
305 PJDLOG_ASSERT(buf != NULL);
306 PJDLOG_ASSERT((size % res->hr_local_sectorsize) == 0);
307 ret = 0;
303 if (pwrite(res->hr_localfd, buf, size, METADATA_SIZE) !=
304 (ssize_t)size) {
305 pjdlog_errno(LOG_ERR, "Unable to flush activemap to disk");
306 res->hr_stat_activemap_write_error++;
308 if (pwrite(res->hr_localfd, buf, size, METADATA_SIZE) !=
309 (ssize_t)size) {
310 pjdlog_errno(LOG_ERR, "Unable to flush activemap to disk");
311 res->hr_stat_activemap_write_error++;
307 return (-1);
312 ret = -1;
308 }
313 }
309 if (res->hr_metaflush == 1 && g_flush(res->hr_localfd) == -1) {
314 if (ret == 0 && res->hr_metaflush == 1 &&
315 g_flush(res->hr_localfd) == -1) {
310 if (errno == EOPNOTSUPP) {
311 pjdlog_warning("The %s provider doesn't support flushing write cache. Disabling it.",
312 res->hr_localpath);
313 res->hr_metaflush = 0;
314 } else {
315 pjdlog_errno(LOG_ERR,
316 "Unable to flush disk cache on activemap update");
317 res->hr_stat_activemap_flush_error++;
316 if (errno == EOPNOTSUPP) {
317 pjdlog_warning("The %s provider doesn't support flushing write cache. Disabling it.",
318 res->hr_localpath);
319 res->hr_metaflush = 0;
320 } else {
321 pjdlog_errno(LOG_ERR,
322 "Unable to flush disk cache on activemap update");
323 res->hr_stat_activemap_flush_error++;
318 return (-1);
324 ret = -1;
319 }
320 }
325 }
326 }
321 return (0);
327 mtx_unlock(&res->hr_amp_diskmap_lock);
328 return (ret);
322}
323
324static bool
325real_remote(const struct hast_resource *res)
326{
327
328 return (strcmp(res->hr_remoteaddr, "none") != 0);
329}

--- 448 unchanged lines hidden (view full) ---

778 * Merge local and remote bitmaps.
779 */
780 activemap_merge(res->hr_amp, map, mapsize);
781 free(map);
782 /*
783 * Now that we merged bitmaps from both nodes, flush it to the
784 * disk before we start to synchronize.
785 */
329}
330
331static bool
332real_remote(const struct hast_resource *res)
333{
334
335 return (strcmp(res->hr_remoteaddr, "none") != 0);
336}

--- 448 unchanged lines hidden (view full) ---

785 * Merge local and remote bitmaps.
786 */
787 activemap_merge(res->hr_amp, map, mapsize);
788 free(map);
789 /*
790 * Now that we merged bitmaps from both nodes, flush it to the
791 * disk before we start to synchronize.
792 */
793 mtx_lock(&res->hr_amp_lock);
786 (void)hast_activemap_flush(res);
787 }
788 nv_free(nvin);
789#ifdef notyet
790 /* Setup directions. */
791 if (proto_send(out, NULL, 0) == -1)
792 pjdlog_errno(LOG_WARNING, "Unable to set connection direction");
793 if (proto_recv(in, NULL, 0) == -1)

--- 489 unchanged lines hidden (view full) ---

1283 mtx_unlock(&range_lock);
1284 break;
1285 }
1286 mtx_lock(&res->hr_amp_lock);
1287 if (activemap_write_start(res->hr_amp,
1288 ggio->gctl_offset, ggio->gctl_length)) {
1289 res->hr_stat_activemap_update++;
1290 (void)hast_activemap_flush(res);
794 (void)hast_activemap_flush(res);
795 }
796 nv_free(nvin);
797#ifdef notyet
798 /* Setup directions. */
799 if (proto_send(out, NULL, 0) == -1)
800 pjdlog_errno(LOG_WARNING, "Unable to set connection direction");
801 if (proto_recv(in, NULL, 0) == -1)

--- 489 unchanged lines hidden (view full) ---

1291 mtx_unlock(&range_lock);
1292 break;
1293 }
1294 mtx_lock(&res->hr_amp_lock);
1295 if (activemap_write_start(res->hr_amp,
1296 ggio->gctl_offset, ggio->gctl_length)) {
1297 res->hr_stat_activemap_update++;
1298 (void)hast_activemap_flush(res);
1299 } else {
1300 mtx_unlock(&res->hr_amp_lock);
1291 }
1301 }
1292 mtx_unlock(&res->hr_amp_lock);
1293 break;
1294 case BIO_DELETE:
1295 res->hr_stat_delete++;
1296 break;
1297 case BIO_FLUSH:
1298 res->hr_stat_flush++;
1299 break;
1300 }

--- 344 unchanged lines hidden (view full) ---

1645 cv_signal(&sync_cond);
1646 continue;
1647 }
1648 if (ggio->gctl_cmd == BIO_WRITE) {
1649 mtx_lock(&res->hr_amp_lock);
1650 if (activemap_need_sync(res->hr_amp, ggio->gctl_offset,
1651 ggio->gctl_length)) {
1652 (void)hast_activemap_flush(res);
1302 break;
1303 case BIO_DELETE:
1304 res->hr_stat_delete++;
1305 break;
1306 case BIO_FLUSH:
1307 res->hr_stat_flush++;
1308 break;
1309 }

--- 344 unchanged lines hidden (view full) ---

1654 cv_signal(&sync_cond);
1655 continue;
1656 }
1657 if (ggio->gctl_cmd == BIO_WRITE) {
1658 mtx_lock(&res->hr_amp_lock);
1659 if (activemap_need_sync(res->hr_amp, ggio->gctl_offset,
1660 ggio->gctl_length)) {
1661 (void)hast_activemap_flush(res);
1662 } else {
1663 mtx_unlock(&res->hr_amp_lock);
1653 }
1664 }
1654 mtx_unlock(&res->hr_amp_lock);
1655 if (hio->hio_replication == HAST_REPLICATION_MEMSYNC)
1656 (void)refcnt_release(&hio->hio_countdown);
1657 }
1658 if (refcnt_release(&hio->hio_countdown) > 0)
1659 continue;
1660 pjdlog_debug(2,
1661 "remote_send: (%p) Moving request to the done queue.",
1662 hio);

--- 250 unchanged lines hidden (view full) ---

1913 ggio->gctl_error = hio->hio_errors[0];
1914 }
1915 if (ggio->gctl_error == 0 && ggio->gctl_cmd == BIO_WRITE) {
1916 mtx_lock(&res->hr_amp_lock);
1917 if (activemap_write_complete(res->hr_amp,
1918 ggio->gctl_offset, ggio->gctl_length)) {
1919 res->hr_stat_activemap_update++;
1920 (void)hast_activemap_flush(res);
1665 if (hio->hio_replication == HAST_REPLICATION_MEMSYNC)
1666 (void)refcnt_release(&hio->hio_countdown);
1667 }
1668 if (refcnt_release(&hio->hio_countdown) > 0)
1669 continue;
1670 pjdlog_debug(2,
1671 "remote_send: (%p) Moving request to the done queue.",
1672 hio);

--- 250 unchanged lines hidden (view full) ---

1923 ggio->gctl_error = hio->hio_errors[0];
1924 }
1925 if (ggio->gctl_error == 0 && ggio->gctl_cmd == BIO_WRITE) {
1926 mtx_lock(&res->hr_amp_lock);
1927 if (activemap_write_complete(res->hr_amp,
1928 ggio->gctl_offset, ggio->gctl_length)) {
1929 res->hr_stat_activemap_update++;
1930 (void)hast_activemap_flush(res);
1931 } else {
1932 mtx_unlock(&res->hr_amp_lock);
1921 }
1933 }
1922 mtx_unlock(&res->hr_amp_lock);
1923 }
1924 if (ggio->gctl_cmd == BIO_WRITE) {
1925 /*
1926 * Unlock range we locked.
1927 */
1928 mtx_lock(&range_lock);
1929 rangelock_del(range_regular, ggio->gctl_offset,
1930 ggio->gctl_length);

--- 79 unchanged lines hidden (view full) ---

2010 offset = activemap_sync_offset(res->hr_amp, &length, &syncext);
2011 if (syncext != -1) {
2012 /*
2013 * We synchronized entire syncext extent, we can mark
2014 * it as clean now.
2015 */
2016 if (activemap_extent_complete(res->hr_amp, syncext))
2017 (void)hast_activemap_flush(res);
1934 }
1935 if (ggio->gctl_cmd == BIO_WRITE) {
1936 /*
1937 * Unlock range we locked.
1938 */
1939 mtx_lock(&range_lock);
1940 rangelock_del(range_regular, ggio->gctl_offset,
1941 ggio->gctl_length);

--- 79 unchanged lines hidden (view full) ---

2021 offset = activemap_sync_offset(res->hr_amp, &length, &syncext);
2022 if (syncext != -1) {
2023 /*
2024 * We synchronized entire syncext extent, we can mark
2025 * it as clean now.
2026 */
2027 if (activemap_extent_complete(res->hr_amp, syncext))
2028 (void)hast_activemap_flush(res);
2029 else
2030 mtx_unlock(&res->hr_amp_lock);
2031 } else {
2032 mtx_unlock(&res->hr_amp_lock);
2018 }
2033 }
2019 mtx_unlock(&res->hr_amp_lock);
2020 if (dorewind) {
2021 dorewind = false;
2022 if (offset == -1)
2023 pjdlog_info("Nodes are in sync.");
2024 else {
2025 pjdlog_info("Synchronization started. %NB to go.",
2026 (intmax_t)(res->hr_extentsize *
2027 activemap_ndirty(res->hr_amp)));

--- 436 unchanged lines hidden ---
2034 if (dorewind) {
2035 dorewind = false;
2036 if (offset == -1)
2037 pjdlog_info("Nodes are in sync.");
2038 else {
2039 pjdlog_info("Synchronization started. %NB to go.",
2040 (intmax_t)(res->hr_extentsize *
2041 activemap_ndirty(res->hr_amp)));

--- 436 unchanged lines hidden ---