source: mainline/uspace/srv/bd/hr/superblock.c@ 75262d2f

Last change on this file since 75262d2f was 10291a23, checked in by Miroslav Cimerman <mc@…>, 7 months ago

hr: FreeBSD GEOM::MIRROR metadata support

  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[b0f1366]1/*
[a57dde4]2 * Copyright (c) 2025 Miroslav Cimerman
[b0f1366]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#include <block.h>
37#include <byteorder.h>
38#include <errno.h>
[ca7fa5b]39#include <inttypes.h>
[b0f1366]40#include <io/log.h>
41#include <loc.h>
42#include <mem.h>
43#include <uuid.h>
44#include <stdlib.h>
45#include <stdio.h>
46#include <str.h>
47
48#include "superblock.h"
49#include "util.h"
50#include "var.h"
51
[10291a23]52#include "metadata/foreign/geom/g_mirror.h"
53#include "metadata/native.h"
54
[50603405]55extern hr_superblock_ops_t metadata_native_ops;
[10291a23]56extern hr_superblock_ops_t metadata_gmirror_ops;
[06f2762]57
[50603405]58static hr_superblock_ops_t *hr_superblock_ops_all[] = {
[10291a23]59 [HR_METADATA_NATIVE] = &metadata_native_ops,
60 [HR_METADATA_GEOM_MIRROR] = &metadata_gmirror_ops
[50603405]61};
[800d188]62
[50603405]63hr_superblock_ops_t *get_type_ops(metadata_type_t type)
[06f2762]64{
[50603405]65 assert(type >= HR_METADATA_NATIVE && type < HR_METADATA_LAST_DUMMY);
[06f2762]66
[50603405]67 return hr_superblock_ops_all[type];
[b422718]68}
69
[50603405]70errno_t find_metadata(service_id_t svc_id, void **rmetadata,
71 metadata_type_t *rtype)
[b0f1366]72{
[a57dde4]73 HR_DEBUG("%s()", __func__);
[b0f1366]74
75 errno_t rc;
[50603405]76 hr_superblock_ops_t *meta_ops;
77 void *meta_block;
78 void *metadata_struct;
[b0f1366]79
[50603405]80 if (rmetadata == NULL)
[b0f1366]81 return EINVAL;
[50603405]82 if (rtype == NULL)
[0277ec2]83 return EINVAL;
84
[50603405]85 volatile metadata_type_t type = HR_METADATA_NATIVE;
86 for (; type < HR_METADATA_LAST_DUMMY; type++) {
87 meta_ops = hr_superblock_ops_all[type];
[0277ec2]88
[50603405]89 metadata_struct = meta_ops->alloc_struct();
90 if (metadata_struct == NULL)
91 return ENOMEM;
[8b51009]92
[50603405]93 rc = meta_ops->get_block(svc_id, &meta_block);
[afec52b4]94 if (rc == ENOMEM) {
95 free(metadata_struct);
[50603405]96 return ENOMEM;
[afec52b4]97 } else if (rc != EOK) {
98 free(metadata_struct);
[50603405]99 continue;
[afec52b4]100 }
[8b51009]101
[10291a23]102 rc = meta_ops->decode(meta_block, metadata_struct);
[8b51009]103
[50603405]104 free(meta_block);
[8b51009]105
[10291a23]106 if (rc != EOK) {
107 free(metadata_struct);
108 continue;
109 }
110
[50603405]111 if (!meta_ops->has_valid_magic(metadata_struct)) {
112 free(metadata_struct);
113 continue;
114 }
[8b51009]115
[50603405]116 *rmetadata = metadata_struct;
117 *rtype = type;
118 return EOK;
[8b51009]119 }
120
[50603405]121 return ENOFS;
[8b51009]122}
123
[b0f1366]124/** @}
125 */
Note: See TracBrowser for help on using the repository browser.