[a3486f2] | 1 | /*
|
---|
| 2 | * Copyright (c) 2025 Miroslav Cimerman
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup hr
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | #ifndef _HR_STRIPE_H
|
---|
| 37 | #define _HR_STRIPE_H
|
---|
| 38 |
|
---|
| 39 | #include <fibril_synch.h>
|
---|
| 40 | #include <errno.h>
|
---|
| 41 | #include <hr.h>
|
---|
| 42 | #include <io/log.h>
|
---|
| 43 |
|
---|
| 44 | #include "io.h"
|
---|
| 45 | #include "var.h"
|
---|
| 46 |
|
---|
| 47 | typedef struct {
|
---|
| 48 | uint64_t start;
|
---|
| 49 | uint64_t end;
|
---|
| 50 | } range_t;
|
---|
| 51 |
|
---|
| 52 | typedef struct hr_stripe {
|
---|
| 53 | hr_volume_t *vol;
|
---|
| 54 | bool write;
|
---|
| 55 | bool subtract;
|
---|
| 56 | size_t strips_touched;
|
---|
| 57 | size_t partial_strips_touched;
|
---|
| 58 | struct {
|
---|
| 59 | range_t range;
|
---|
| 60 | uint64_t cnt;
|
---|
| 61 | uint64_t strip_off;
|
---|
| 62 | const void *data_write;
|
---|
| 63 | void *data_read;
|
---|
| 64 | } *extent_span;
|
---|
| 65 | uint64_t p_extent; /* parity extent index for this stripe */
|
---|
| 66 |
|
---|
| 67 | hr_fgroup_t *worker_group;
|
---|
| 68 |
|
---|
| 69 | errno_t rc;
|
---|
| 70 | bool abort;
|
---|
| 71 | bool done;
|
---|
| 72 |
|
---|
| 73 | fibril_mutex_t parity_lock;
|
---|
| 74 | uint8_t *parity; /* the actual parity strip */
|
---|
| 75 |
|
---|
| 76 | /* parity writers waiting until this many parity commits */
|
---|
| 77 | size_t ps_to_be_added;
|
---|
| 78 | size_t ps_added; /* number of parities commited to stripe */
|
---|
| 79 | fibril_condvar_t ps_added_cv;
|
---|
| 80 | bool p_count_final;
|
---|
| 81 |
|
---|
| 82 | /*
|
---|
| 83 | * Possibly need 2 ranges because single IO that partially spans
|
---|
| 84 | * 2 strips and overflows to second one without creating an adjacent
|
---|
| 85 | * range results in parity not being continous.
|
---|
| 86 | *
|
---|
| 87 | * Example: 2+1 extents, 4 block strip, last extent parity
|
---|
| 88 | *
|
---|
| 89 | * E0 E1 P
|
---|
| 90 | * +----+ +----+ +-----+
|
---|
| 91 | * | | | IO | | IOP |
|
---|
| 92 | * |----| |----| |-----|
|
---|
| 93 | * | | | | | |
|
---|
| 94 | * |----| |----| |-----|
|
---|
| 95 | * | | | | | |
|
---|
| 96 | * |----| |----| |-----|
|
---|
| 97 | * | IO | | | | IOP |
|
---|
| 98 | * +----+ +----+ +-----+
|
---|
| 99 | *
|
---|
| 100 | * - need 2 parity writers
|
---|
| 101 | */
|
---|
| 102 | range_t total_height[2]; /* for knowing writing parity range(s) */
|
---|
| 103 | size_t range_count;
|
---|
| 104 | } hr_stripe_t;
|
---|
| 105 |
|
---|
| 106 | extern hr_stripe_t *hr_create_stripes(hr_volume_t *, size_t, bool);
|
---|
| 107 | extern void hr_destroy_stripes(hr_stripe_t *, size_t);
|
---|
| 108 | extern void hr_stripe_commit_parity(hr_stripe_t *, uint64_t, const void *,
|
---|
| 109 | uint64_t);
|
---|
| 110 | extern void hr_stripe_wait_for_parity_commits(hr_stripe_t *);
|
---|
| 111 | extern void hr_stripe_parity_abort(hr_stripe_t *);
|
---|
| 112 | extern void execute_stripe(hr_stripe_t *, size_t);
|
---|
| 113 | extern void wait_for_stripe(hr_stripe_t *);
|
---|
| 114 |
|
---|
| 115 | #endif
|
---|
| 116 |
|
---|
| 117 | /** @}
|
---|
| 118 | */
|
---|