| [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 */
|
|---|
| [cdfcaea] | 75 | uint64_t parity_size;
|
|---|
| [a3486f2] | 76 |
|
|---|
| 77 | /* parity writers waiting until this many parity commits */
|
|---|
| 78 | size_t ps_to_be_added;
|
|---|
| 79 | size_t ps_added; /* number of parities commited to stripe */
|
|---|
| 80 | fibril_condvar_t ps_added_cv;
|
|---|
| 81 | bool p_count_final;
|
|---|
| 82 |
|
|---|
| 83 | /*
|
|---|
| 84 | * Possibly need 2 ranges because single IO that partially spans
|
|---|
| 85 | * 2 strips and overflows to second one without creating an adjacent
|
|---|
| 86 | * range results in parity not being continous.
|
|---|
| 87 | *
|
|---|
| 88 | * Example: 2+1 extents, 4 block strip, last extent parity
|
|---|
| 89 | *
|
|---|
| 90 | * E0 E1 P
|
|---|
| 91 | * +----+ +----+ +-----+
|
|---|
| 92 | * | | | IO | | IOP |
|
|---|
| 93 | * |----| |----| |-----|
|
|---|
| 94 | * | | | | | |
|
|---|
| 95 | * |----| |----| |-----|
|
|---|
| 96 | * | | | | | |
|
|---|
| 97 | * |----| |----| |-----|
|
|---|
| 98 | * | IO | | | | IOP |
|
|---|
| 99 | * +----+ +----+ +-----+
|
|---|
| 100 | *
|
|---|
| 101 | * - need 2 parity writers
|
|---|
| 102 | */
|
|---|
| 103 | range_t total_height[2]; /* for knowing writing parity range(s) */
|
|---|
| 104 | size_t range_count;
|
|---|
| 105 | } hr_stripe_t;
|
|---|
| 106 |
|
|---|
| [cdfcaea] | 107 | extern hr_stripe_t *hr_create_stripes(hr_volume_t *, uint64_t, size_t, bool);
|
|---|
| [a3486f2] | 108 | extern void hr_destroy_stripes(hr_stripe_t *, size_t);
|
|---|
| [cdfcaea] | 109 | extern void hr_reset_stripe(hr_stripe_t *);
|
|---|
| [a3486f2] | 110 | extern void hr_stripe_commit_parity(hr_stripe_t *, uint64_t, const void *,
|
|---|
| 111 | uint64_t);
|
|---|
| 112 | extern void hr_stripe_wait_for_parity_commits(hr_stripe_t *);
|
|---|
| 113 | extern void hr_stripe_parity_abort(hr_stripe_t *);
|
|---|
| 114 | extern void execute_stripe(hr_stripe_t *, size_t);
|
|---|
| 115 | extern void wait_for_stripe(hr_stripe_t *);
|
|---|
| 116 |
|
|---|
| 117 | #endif
|
|---|
| 118 |
|
|---|
| 119 | /** @}
|
|---|
| 120 | */
|
|---|