Changeset ca127f37 in mainline


Ignore:
Timestamp:
2024-09-07T18:33:36Z (9 days ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
430442d, 47bfcfb, de4f165, e132103b
Parents:
e90019d
Message:

Persist volume configuration

Location:
uspace
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sysinst/sysinst.c

    re90019d rca127f37  
    279279        }
    280280
    281         rv = asprintf(&path, "%s%s", rdpath, "/cfg/volsrv.sif");
     281        rv = asprintf(&path, "%s%s", rdpath, "/cfg/initvol.sif");
    282282        if (rv < 0) {
    283283                rc = ENOMEM;
  • uspace/srv/volsrv/part.c

    re90019d rca127f37  
    5252#include "types/part.h"
    5353#include "volume.h"
     54#include "volsrv.h"
    5455
    5556static errno_t vol_part_add_locked(vol_parts_t *, service_id_t);
     
    403404        part->cur_mp_auto = mp_auto;
    404405
     406        if (str_cmp(mp, "/w") == 0) {
     407                log_msg(LOG_DEFAULT, LVL_NOTE, "Mounted system volume - "
     408                    "loading additional configuration.");
     409                rc = vol_volumes_merge_to(part->parts->volumes,
     410                    vol_cfg_file);
     411                if (rc != EOK) {
     412                        log_msg(LOG_DEFAULT, LVL_ERROR, "Error loading "
     413                            "additional configuration.");
     414                        return rc;
     415                }
     416        }
     417
    405418        return rc;
    406419}
  • uspace/srv/volsrv/volsrv.c

    re90019d rca127f37  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5353#define NAME  "volsrv"
    5454
    55 const char *vol_cfg_file = "/cfg/volsrv.sif";
     55const char *vol_icfg_file = "/cfg/initvol.sif";
     56const char *vol_cfg_file = "/w/cfg/volsrv.sif";
    5657
    5758static void vol_client_conn(ipc_call_t *, void *);
     
    6667        log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_init()");
    6768
    68         rc = vol_volumes_create(vol_cfg_file, &volumes);
     69        rc = vol_volumes_create(vol_icfg_file, &volumes);
    6970        if (rc != EOK)
    7071                goto error;
  • uspace/srv/volsrv/volume.c

    re90019d rca127f37  
    185185                free(volumes);
    186186
     187        return rc;
     188}
     189
     190/** Merge list of volumes into new file.
     191 *
     192 * @param volumes List of volumes
     193 * @param cfg_path Path to file containing configuration repository in SIF
     194 * @return EOK on success, ENOMEM if out of memory
     195 */
     196errno_t vol_volumes_merge_to(vol_volumes_t *volumes, const char *cfg_path)
     197{
     198        sif_doc_t *doc = NULL;
     199        sif_node_t *node;
     200        const char *ntype;
     201        char *dcfg_path;
     202        errno_t rc;
     203
     204        dcfg_path = str_dup(cfg_path);
     205        if (dcfg_path == NULL) {
     206                rc = ENOMEM;
     207                goto error;
     208        }
     209
     210        free(volumes->cfg_path);
     211        volumes->cfg_path = dcfg_path;
     212
     213        /* Try opening existing repository */
     214        rc = sif_load(cfg_path, &doc);
     215        if (rc != EOK) {
     216                /* Failed to open existing, create new repository */
     217                rc = vol_volumes_sync(volumes);
     218                if (rc != EOK)
     219                        goto error;
     220        } else {
     221                /*
     222                 * Loaded existing configuration. Find 'volumes' node, should
     223                 * be the first child of the root node.
     224                 */
     225                node = sif_node_first_child(sif_get_root(doc));
     226
     227                /* Verify it's the correct node type */
     228                ntype = sif_node_get_type(node);
     229                if (str_cmp(ntype, "volumes") != 0) {
     230                        rc = EIO;
     231                        goto error;
     232                }
     233
     234                rc = vol_volumes_load(node, volumes);
     235                if (rc != EOK)
     236                        goto error;
     237
     238                sif_delete(doc);
     239        }
     240
     241        return EOK;
     242error:
     243        if (doc != NULL)
     244                (void) sif_delete(doc);
    187245        return rc;
    188246}
  • uspace/srv/volsrv/volume.h

    re90019d rca127f37  
    4242
    4343extern errno_t vol_volumes_create(const char *, vol_volumes_t **);
     44extern errno_t vol_volumes_merge_to(vol_volumes_t *, const char *);
    4445extern errno_t vol_volumes_sync(vol_volumes_t *);
    4546extern void vol_volumes_destroy(vol_volumes_t *);
Note: See TracChangeset for help on using the changeset viewer.