source: mainline/uspace/srv/bd/hr/superblock.c@ 372a9fc

Last change on this file since 372a9fc was 50603405, checked in by Miroslav Cimerman <mc@…>, 7 months ago

hr: metadata format agnostic superblock ops

Put metadata specific code behind a new hr_superblock_ops_t
interface, that allows to easily add support for new metadata
formats.

  • Property mode set to 100644
File size: 3.0 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
[50603405]48#include "metadata/native.h"
[b0f1366]49#include "superblock.h"
50#include "util.h"
51#include "var.h"
52
[50603405]53extern hr_superblock_ops_t metadata_native_ops;
[06f2762]54
[50603405]55static hr_superblock_ops_t *hr_superblock_ops_all[] = {
56 [HR_METADATA_NATIVE] = &metadata_native_ops
57};
[800d188]58
[50603405]59hr_superblock_ops_t *get_type_ops(metadata_type_t type)
[06f2762]60{
[50603405]61 assert(type >= HR_METADATA_NATIVE && type < HR_METADATA_LAST_DUMMY);
[06f2762]62
[50603405]63 return hr_superblock_ops_all[type];
[b422718]64}
65
[50603405]66errno_t find_metadata(service_id_t svc_id, void **rmetadata,
67 metadata_type_t *rtype)
[b0f1366]68{
[a57dde4]69 HR_DEBUG("%s()", __func__);
[b0f1366]70
71 errno_t rc;
[50603405]72 hr_superblock_ops_t *meta_ops;
73 void *meta_block;
74 void *metadata_struct;
[b0f1366]75
[50603405]76 if (rmetadata == NULL)
[b0f1366]77 return EINVAL;
[50603405]78 if (rtype == NULL)
[0277ec2]79 return EINVAL;
80
[50603405]81 volatile metadata_type_t type = HR_METADATA_NATIVE;
82 for (; type < HR_METADATA_LAST_DUMMY; type++) {
83 meta_ops = hr_superblock_ops_all[type];
[0277ec2]84
[50603405]85 metadata_struct = meta_ops->alloc_struct();
86 if (metadata_struct == NULL)
87 return ENOMEM;
[8b51009]88
[50603405]89 rc = meta_ops->get_block(svc_id, &meta_block);
90 if (rc == ENOMEM)
91 return ENOMEM;
92 if (rc != EOK)
93 continue;
[8b51009]94
[50603405]95 meta_ops->decode(meta_block, metadata_struct);
[8b51009]96
[50603405]97 free(meta_block);
[8b51009]98
[50603405]99 if (!meta_ops->has_valid_magic(metadata_struct)) {
100 free(metadata_struct);
101 continue;
102 }
[8b51009]103
[50603405]104 *rmetadata = metadata_struct;
105 *rtype = type;
106 return EOK;
[8b51009]107 }
108
[50603405]109 return ENOFS;
[8b51009]110}
111
[b0f1366]112/** @}
113 */
Note: See TracBrowser for help on using the repository browser.