Changeset 7fba146 in mainline
- Timestamp:
- 2025-06-09T23:41:50Z (7 days ago)
- Children:
- 6791fbf
- Parents:
- 83ff12f
- Location:
- uspace/srv/bd/hr
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/hr/metadata/foreign/geom/hr_g_mirror.c
r83ff12f r7fba146 62 62 static bool meta_gmirror_has_valid_magic(const void *); 63 63 static bool meta_gmirror_compare_uuids(const void *, const void *); 64 static void meta_gmirror_inc_counter( void*);64 static void meta_gmirror_inc_counter(hr_volume_t *); 65 65 static errno_t meta_gmirror_save(hr_volume_t *, bool); 66 66 static const char *meta_gmirror_get_devname(const void *); … … 284 284 } 285 285 286 static void meta_gmirror_inc_counter(void *md_v) 287 { 288 struct g_mirror_metadata *md = md_v; 286 static void meta_gmirror_inc_counter(hr_volume_t *vol) 287 { 288 fibril_mutex_lock(&vol->md_lock); 289 290 struct g_mirror_metadata *md = vol->in_mem_md; 289 291 290 292 /* XXX: probably md_genid and not md_syncid is incremented */ 291 293 md->md_genid++; 294 295 fibril_mutex_unlock(&vol->md_lock); 292 296 } 293 297 -
uspace/srv/bd/hr/metadata/foreign/geom/hr_g_stripe.c
r83ff12f r7fba146 62 62 static bool meta_gstripe_has_valid_magic(const void *); 63 63 static bool meta_gstripe_compare_uuids(const void *, const void *); 64 static void meta_gstripe_inc_counter( void*);64 static void meta_gstripe_inc_counter(hr_volume_t *); 65 65 static errno_t meta_gstripe_save(hr_volume_t *, bool); 66 66 static const char *meta_gstripe_get_devname(const void *); … … 286 286 } 287 287 288 static void meta_gstripe_inc_counter( void *md_v)289 { 290 (void) md_v;288 static void meta_gstripe_inc_counter(hr_volume_t *vol) 289 { 290 (void)vol; 291 291 } 292 292 -
uspace/srv/bd/hr/metadata/foreign/softraid/hr_softraid.c
r83ff12f r7fba146 62 62 static bool meta_softraid_has_valid_magic(const void *); 63 63 static bool meta_softraid_compare_uuids(const void *, const void *); 64 static void meta_softraid_inc_counter( void*);64 static void meta_softraid_inc_counter(hr_volume_t *); 65 65 static errno_t meta_softraid_save(hr_volume_t *, bool); 66 66 static const char *meta_softraid_get_devname(const void *); … … 419 419 } 420 420 421 static void meta_softraid_inc_counter(void *md_v) 422 { 423 struct sr_metadata *md = md_v; 421 static void meta_softraid_inc_counter(hr_volume_t *vol) 422 { 423 fibril_mutex_lock(&vol->md_lock); 424 425 struct sr_metadata *md = vol->in_mem_md; 424 426 425 427 md->ssd_ondisk++; 428 429 fibril_mutex_unlock(&vol->md_lock); 426 430 } 427 431 -
uspace/srv/bd/hr/metadata/native.c
r83ff12f r7fba146 63 63 static bool meta_native_has_valid_magic(const void *); 64 64 static bool meta_native_compare_uuids(const void *, const void *); 65 static void meta_native_inc_counter( void*);65 static void meta_native_inc_counter(hr_volume_t *); 66 66 static errno_t meta_native_save(hr_volume_t *, bool); 67 67 static const char *meta_native_get_devname(const void *); … … 365 365 } 366 366 367 static void meta_native_inc_counter(void *md_v) 368 { 369 hr_metadata_t *md = md_v; 367 static void meta_native_inc_counter(hr_volume_t *vol) 368 { 369 fibril_mutex_lock(&vol->md_lock); 370 371 hr_metadata_t *md = vol->in_mem_md; 370 372 371 373 md->counter++; 374 375 fibril_mutex_unlock(&vol->md_lock); 372 376 } 373 377 … … 409 413 meta_native_encode(md, md_block); 410 414 rc = meta_native_write_block(ext->svc_id, md_block); 411 if ( with_state_callback && rc != EOK)415 if (rc != EOK && with_state_callback) 412 416 vol->hr_ops.ext_state_cb(vol, i, rc); 413 417 } -
uspace/srv/bd/hr/raid1.c
r83ff12f r7fba146 56 56 #include "var.h" 57 57 58 static void hr_raid1_vol_state_eval_forced(hr_volume_t *); 58 59 static size_t hr_raid1_count_good_extents(hr_volume_t *, uint64_t, size_t, 59 60 uint64_t); … … 105 106 new_volume->hr_bds.sarg = new_volume; 106 107 107 /* force volume state update */ 108 hr_mark_vol_state_dirty(new_volume); 109 hr_raid1_vol_state_eval(new_volume); 108 hr_raid1_vol_state_eval_forced(new_volume); 110 109 111 110 fibril_rwlock_read_lock(&new_volume->states_lock); … … 155 154 bool exp = true; 156 155 157 /* TODO: could also wrap this */158 156 if (!atomic_compare_exchange_strong(&vol->state_dirty, &exp, false)) 159 157 return; 160 158 161 fibril_mutex_lock(&vol->md_lock); 162 163 vol->meta_ops->inc_counter(vol->in_mem_md); 164 /* XXX: save right away */ 165 166 fibril_mutex_unlock(&vol->md_lock); 159 vol->meta_ops->inc_counter(vol); 160 (void)vol->meta_ops->save(vol, WITH_STATE_CALLBACK); 161 162 hr_raid1_vol_state_eval_forced(vol); 163 } 164 165 void hr_raid1_ext_state_cb(hr_volume_t *vol, size_t extent, 166 errno_t rc) 167 { 168 HR_DEBUG("%s()", __func__); 169 170 if (rc == EOK) 171 return; 172 173 assert(fibril_rwlock_is_locked(&vol->extents_lock)); 174 175 fibril_rwlock_write_lock(&vol->states_lock); 176 177 switch (rc) { 178 case ENOMEM: 179 hr_update_ext_state(vol, extent, HR_EXT_INVALID); 180 break; 181 case ENOENT: 182 hr_update_ext_state(vol, extent, HR_EXT_MISSING); 183 break; 184 default: 185 hr_update_ext_state(vol, extent, HR_EXT_FAILED); 186 } 187 188 hr_mark_vol_state_dirty(vol); 189 190 fibril_rwlock_write_unlock(&vol->states_lock); 191 } 192 193 static void hr_raid1_vol_state_eval_forced(hr_volume_t *vol) 194 { 195 HR_DEBUG("%s()", __func__); 167 196 168 197 fibril_rwlock_read_lock(&vol->extents_lock); … … 209 238 } 210 239 211 void hr_raid1_ext_state_cb(hr_volume_t *vol, size_t extent,212 errno_t rc)213 {214 HR_DEBUG("%s()", __func__);215 216 if (rc == EOK)217 return;218 219 assert(fibril_rwlock_is_locked(&vol->extents_lock));220 221 fibril_rwlock_write_lock(&vol->states_lock);222 223 switch (rc) {224 case ENOMEM:225 hr_update_ext_state(vol, extent, HR_EXT_INVALID);226 break;227 case ENOENT:228 hr_update_ext_state(vol, extent, HR_EXT_MISSING);229 break;230 default:231 hr_update_ext_state(vol, extent, HR_EXT_FAILED);232 }233 234 hr_mark_vol_state_dirty(vol);235 236 fibril_rwlock_write_unlock(&vol->states_lock);237 }238 239 240 static errno_t hr_raid1_bd_open(bd_srvs_t *bds, bd_srv_t *bd) 240 241 { … … 328 329 if (vol_state == HR_VOL_FAULTY || vol_state == HR_VOL_NONE) 329 330 return EIO; 331 332 if (!vol->data_dirty && type == HR_BD_WRITE) { 333 vol->meta_ops->inc_counter(vol); 334 vol->data_dirty = true; 335 } 330 336 331 337 if (type == HR_BD_READ || type == HR_BD_WRITE) … … 543 549 fibril_rwlock_write_unlock(&vol->states_lock); 544 550 545 rc =vol->meta_ops->save(vol, WITH_STATE_CALLBACK);551 (void)vol->meta_ops->save(vol, WITH_STATE_CALLBACK); 546 552 547 553 end: -
uspace/srv/bd/hr/superblock.c
r83ff12f r7fba146 50 50 #include "var.h" 51 51 52 #include "metadata/native.h" 53 52 54 #include "metadata/foreign/geom/g_mirror.h" 53 55 #include "metadata/foreign/geom/g_stripe.h" 54 56 #include "metadata/foreign/softraid/softraidvar.h" 55 56 #include "metadata/native.h"57 57 58 58 extern hr_superblock_ops_t metadata_native_ops; -
uspace/srv/bd/hr/superblock.h
r83ff12f r7fba146 54 54 bool (*has_valid_magic)(const void *); 55 55 bool (*compare_uuids)(const void *, const void *); 56 void (*inc_counter)( void*);56 void (*inc_counter)(hr_volume_t *); 57 57 errno_t (*save)(hr_volume_t *, bool); 58 58 const char *(*get_devname)(const void *); -
uspace/srv/bd/hr/util.c
r83ff12f r7fba146 151 151 fibril_mutex_initialize(&vol->range_lock_list_lock); 152 152 153 atomic_init(&vol->state_dirty, false); 154 atomic_init(&vol->data_dirty, false); 153 155 atomic_init(&vol->rebuild_blk, 0); 154 atomic_init(&vol->state_dirty, false);155 156 atomic_init(&vol->open_cnt, 0); 156 157 … … 857 858 meta_ops->init_meta2vol(list, vol); 858 859 859 /*860 * TODO: something like mark md dirty or whatever861 * - probably will be handled by each md type differently,862 * by specific function pointers863 * - deal with this when foreign md will be handled864 *865 * XXX: if thats the only thing that can change in metadata866 * during volume runtime, then whatever, but if more867 * things will need to be synced, think of something more clever868 *869 * TODO: remove from here and increment it the "first" time (if nothing870 * happens - no state changes, no rebuild, etc) - only after the first871 * write... but for now leave it here872 */873 (void)vol->meta_ops->inc_counter(vol->in_mem_md);874 875 860 rc = vol->hr_ops.create(vol); 876 861 if (rc != EOK) 877 862 goto error; 878 863 879 /*880 * XXX: register it here881 * ... if it fails on EEXIST try different name... like + 1 on the end882 *883 * or have metadata edit utility as a part of hrctl..., or create884 * the original name + 4 random characters, tell the user that the device885 * was created with this new name, and add a option to hrctl to rename886 * an active array, and then write the new dirty metadata...887 *888 * or just refuse to assemble a name that is already used...889 *890 * TODO: discuss891 */892 864 rc = hr_register_volume(vol); 893 865 if (rc != EOK) 894 866 goto error; 895 896 (void)vol->meta_ops->save(vol, WITH_STATE_CALLBACK);897 867 898 868 fibril_rwlock_write_lock(&hr_volumes_lock); -
uspace/srv/bd/hr/var.h
r83ff12f r7fba146 101 101 _Atomic bool state_dirty; /* dirty state */ 102 102 103 /* 104 * used to increment metadata counter on first write, 105 * allowing non-destructive read-only access 106 */ 107 _Atomic bool data_dirty; 108 103 109 /* XXX: atomic_uint_least64_t? */ 104 110 _Atomic uint64_t rebuild_blk; /* rebuild position */
Note:
See TracChangeset
for help on using the changeset viewer.