Changeset 1dcba91 in mainline


Ignore:
Timestamp:
2018-08-08T10:08:53Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
44428bb
Parents:
7ab7075f
git-author:
Jiri Svoboda <jiri@…> (2018-08-07 17:07:59)
git-committer:
Jiri Svoboda <jiri@…> (2018-08-08 10:08:53)
Message:

Configuration repository for volume server.

Files:
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • boot/Makefile

    r7ab7075f r1dcba91  
    4040        mkdir -p "$(DIST_PATH)/app/"
    4141        mkdir -p "$(DIST_PATH)/cfg/net/"
     42        mkdir -p "$(DIST_PATH)/data/cfg/"
    4243        mkdir -p "$(DIST_PATH)/lib/"
    4344        mkdir -p "$(DIST_PATH)/loc/"
     
    4647        mkdir -p "$(DIST_PATH)/test/"
    4748        mkdir -p "$(DIST_PATH)/tmp/"
     49        mkdir -p "$(DIST_PATH)/vol/"
    4850        for file in $(RD_SRVS) ; do \
    4951                cp "$$file" "$(DIST_PATH)/srv/" ; \
  • uspace/app/contacts/contacts.c

    r7ab7075f r1dcba91  
    7878} contact_action_t;
    7979
    80 static errno_t contacts_unmarshal(sif_node_t *, contacts_t *);
     80static errno_t contacts_load(sif_node_t *, contacts_t *);
    8181static contacts_entry_t *contacts_first(contacts_t *);
    8282static contacts_entry_t *contacts_next(contacts_entry_t *);
     
    150150                }
    151151
    152                 rc = contacts_unmarshal(node, contacts);
    153                 if (rc != EOK)
    154                         goto error;
    155 
    156                 contacts->nentries = node;
     152                rc = contacts_load(node, contacts);
     153                if (rc != EOK)
     154                        goto error;
    157155        }
    158156
     
    171169}
    172170
    173 /** Unmarshal contact entries from SIF repository.
     171/** Load contact entries from SIF repository.
    174172 *
    175173 * @param nentries Entries node
    176  * @param contacts Contacts object to unmarshal to
     174 * @param contacts Contacts object to load to
    177175 * @return EOK on success or error code
    178176 */
    179 static errno_t contacts_unmarshal(sif_node_t *nentries, contacts_t *contacts)
     177static errno_t contacts_load(sif_node_t *nentries, contacts_t *contacts)
    180178{
    181179        sif_node_t *nentry;
  • uspace/lib/sif/private/sif.h

    r7ab7075f r1dcba91  
    4444/** SIF session */
    4545struct sif_sess {
    46         /** Backing file */
     46        /** Repository file */
    4747        FILE *f;
     48        /** Repository file name */
     49        char *fname;
    4850        /** Root node */
    4951        struct sif_node *root;
  • uspace/lib/sif/src/sif.c

    r7ab7075f r1dcba91  
    191191                return ENOMEM;
    192192
     193        sess->fname = str_dup(fname);
     194        if (sess->fname == NULL) {
     195                rc = ENOMEM;
     196                goto error;
     197        }
     198
    193199        root = sif_node_new(NULL);
    194200        if (root == NULL) {
     
    227233                sif_trans_abort(trans);
    228234        sif_node_delete(root);
     235        if (sess->fname != NULL)
     236                free(sess->fname);
    229237        free(sess);
    230238        return rc;
     
    249257                return ENOMEM;
    250258
    251         f = fopen(fname, "r+");
     259        sess->fname = str_dup(fname);
     260        if (sess->fname == NULL) {
     261                rc = ENOMEM;
     262                goto error;
     263        }
     264
     265        f = fopen(fname, "r");
    252266        if (f == NULL) {
    253267                rc = EIO;
     
    272286error:
    273287        sif_node_delete(root);
     288        if (sess->fname != NULL)
     289                free(sess->fname);
    274290        free(sess);
    275291        return rc;
     
    290306        }
    291307
     308        if (sess->fname != NULL)
     309                free(sess->fname);
     310        free(sess);
    292311        return EOK;
    293312}
     
    394413        errno_t rc;
    395414
    396         rewind(trans->sess->f);
     415        (void) fclose(trans->sess->f);
     416
     417        trans->sess->f = fopen(trans->sess->fname, "w");
     418        if (trans->sess->f == NULL)
     419                return EIO;
    397420
    398421        rc = sif_export_node(trans->sess->root, trans->sess->f);
    399422        if (rc != EOK)
    400423                return rc;
     424
     425        if (fputc('\n', trans->sess->f) == EOF)
     426                return EIO;
     427
     428        if (fflush(trans->sess->f) == EOF)
     429                return EIO;
    401430
    402431        free(trans);
  • uspace/srv/volsrv/Makefile

    r7ab7075f r1dcba91  
    2929USPACE_PREFIX = ../..
    3030
    31 LIBS = label block
     31LIBS =  block label sif
    3232
    3333BINARY = volsrv
  • uspace/srv/volsrv/test/volume.c

    r7ab7075f r1dcba91  
    2929#include <errno.h>
    3030#include <pcut/pcut.h>
     31#include <stdio.h>
    3132#include <str.h>
    3233
     
    4142{
    4243        vol_volumes_t *volumes;
     44        char *namebuf;
     45        char *fname;
    4346        errno_t rc;
     47        int rv;
    4448
    45         rc = vol_volumes_create(&volumes);
     49        namebuf = malloc(L_tmpnam);
     50        PCUT_ASSERT_NOT_NULL(namebuf);
     51
     52        fname = tmpnam(namebuf);
     53        PCUT_ASSERT_NOT_NULL(fname);
     54
     55        rc = vol_volumes_create(fname, &volumes);
    4656        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    4757
    4858        vol_volumes_destroy(volumes);
     59        rv = remove(fname);
     60        PCUT_ASSERT_INT_EQUALS(0, rv);
     61        free(fname);
    4962}
    5063
     
    5467        vol_volumes_t *volumes;
    5568        vol_volume_t *va, *vb, *va1;
     69        char *namebuf;
     70        char *fname;
    5671        errno_t rc;
     72        int rv;
    5773
    58         rc = vol_volumes_create(&volumes);
     74        namebuf = malloc(L_tmpnam);
     75        PCUT_ASSERT_NOT_NULL(namebuf);
     76
     77        fname = tmpnam(namebuf);
     78        PCUT_ASSERT_NOT_NULL(fname);
     79
     80        rc = vol_volumes_create(fname, &volumes);
    5981        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    6082
     
    7597
    7698        vol_volumes_destroy(volumes);
     99        rv = remove(fname);
     100        PCUT_ASSERT_INT_EQUALS(0, rv);
     101        free(fname);
    77102}
    78103
     
    82107        vol_volumes_t *volumes;
    83108        vol_volume_t *va;
     109        char *namebuf;
     110        char *fname;
    84111        errno_t rc;
     112        int rv;
    85113
    86         rc = vol_volumes_create(&volumes);
     114        namebuf = malloc(L_tmpnam);
     115        PCUT_ASSERT_NOT_NULL(namebuf);
     116
     117        fname = tmpnam(namebuf);
     118        PCUT_ASSERT_NOT_NULL(fname);
     119
     120        rc = vol_volumes_create(fname, &volumes);
    87121        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    88122
     
    108142
    109143        vol_volumes_destroy(volumes);
     144        rv = remove(fname);
     145        PCUT_ASSERT_INT_EQUALS(0, rv);
     146        free(fname);
    110147}
    111148
  • uspace/srv/volsrv/types/volume.h

    r7ab7075f r1dcba91  
    4141#include <atomic.h>
    4242#include <fibril_synch.h>
     43#include <sif.h>
    4344
    4445/** Volume */
     
    5455        /** Mount point */
    5556        char *mountp;
     57        /** SIF node for this volume */
     58        sif_node_t *nvolume;
    5659} vol_volume_t;
    5760
    58 /** Partitions */
     61/** Volumes */
    5962typedef struct vol_volumes {
    6063        /** Synchronize access to list of volumes */
     
    6265        /** Volumes (list of vol_volume_t) */
    6366        list_t volumes;
     67        /** Cconfiguration repo session */
     68        sif_sess_t *repo;
     69        /** Volumes SIF node */
     70        sif_node_t *nvolumes;
    6471} vol_volumes_t;
    6572
  • uspace/srv/volsrv/volsrv.c

    r7ab7075f r1dcba91  
    5353#define NAME  "volsrv"
    5454
     55const char *vol_cfg_file = "/data/cfg/volsrv.sif";
     56
    5557static void vol_client_conn(ipc_call_t *, void *);
    5658
     
    6365        log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_init()");
    6466
    65         rc = vol_volumes_create(&volumes);
     67        rc = vol_volumes_create(vol_cfg_file, &volumes);
    6668        if (rc != EOK)
    6769                goto error;
  • uspace/srv/volsrv/volume.c

    r7ab7075f r1dcba91  
    5959static errno_t vol_volume_lookup_ref_locked(vol_volumes_t *, const char *,
    6060    vol_volume_t **);
     61static errno_t vol_volumes_load(sif_node_t *, vol_volumes_t *);
    6162
    6263/** Allocate new volume structure.
     
    104105/** Create list of volumes.
    105106 *
     107 * @param cfg_path Path to file containing configuration repository in SIF
    106108 * @param rvolumes Place to store pointer to list of volumes.
    107109 * @return EOK on success, ENOMEM if out of memory
    108110 */
    109 errno_t vol_volumes_create(vol_volumes_t **rvolumes)
     111errno_t vol_volumes_create(const char *cfg_path,
     112    vol_volumes_t **rvolumes)
    110113{
    111114        vol_volumes_t *volumes;
     115        sif_sess_t *repo = NULL;
     116        sif_trans_t *trans = NULL;
     117        sif_node_t *node;
     118        const char *ntype;
     119        errno_t rc;
    112120
    113121        volumes = calloc(1, sizeof(vol_volumes_t));
     
    118126        list_initialize(&volumes->volumes);
    119127
     128        /* Try opening existing repository */
     129        rc = sif_open(cfg_path, &repo);
     130        if (rc != EOK) {
     131                /* Failed to open existing, create new repository */
     132                rc = sif_create(cfg_path, &repo);
     133                if (rc != EOK)
     134                        goto error;
     135
     136                rc = sif_trans_begin(repo, &trans);
     137                if (rc != EOK)
     138                        goto error;
     139
     140                /* Create 'volumes' node. */
     141                rc = sif_node_append_child(trans, sif_get_root(repo),
     142                    "volumes", &volumes->nvolumes);
     143                if (rc != EOK)
     144                        goto error;
     145
     146                rc = sif_trans_end(trans);
     147                if (rc != EOK)
     148                        goto error;
     149
     150                trans = NULL;
     151        } else {
     152                /*
     153                 * Opened existing repo. Find 'volumes' node, should be
     154                 * the first child of the root node.
     155                 */
     156                node = sif_node_first_child(sif_get_root(repo));
     157
     158                /* Verify it's the correct node type */
     159                ntype = sif_node_get_type(node);
     160                if (str_cmp(ntype, "volumes") != 0) {
     161                        rc = EIO;
     162                        goto error;
     163                }
     164
     165                rc = vol_volumes_load(node, volumes);
     166                if (rc != EOK)
     167                        goto error;
     168        }
     169
     170        volumes->repo = repo;
    120171        *rvolumes = volumes;
     172
    121173        return EOK;
     174error:
     175        if (trans != NULL)
     176                sif_trans_abort(trans);
     177        if (repo != NULL)
     178                (void) sif_close(repo);
     179        if (volumes != NULL)
     180                free(volumes);
     181
     182        return rc;
    122183}
    123184
     
    195256                return ENOMEM;
    196257
     258        free(volume->label);
    197259        volume->label = str_dup(label);
     260
     261        if (volume->label == NULL) {
     262                vol_volume_delete(volume);
     263                return ENOMEM;
     264        }
     265
    198266        vol_volume_add_locked(volumes, volume);
    199267
     
    260328{
    261329        char *mp;
     330        char *old_mp;
     331        errno_t rc;
     332        sif_trans_t *trans = NULL;
     333        sif_node_t *nvolume;
    262334
    263335        mp = str_dup(mountp);
     
    265337                return ENOMEM;
    266338
    267         free(volume->mountp);
     339        old_mp = volume->mountp;
    268340        volume->mountp = mp;
    269341
     342        if (vol_volume_is_persist(volume)) {
     343                /* Volume is now persistent */
     344                if (volume->nvolume == NULL) {
     345                        /* Create volume node */
     346                        rc = sif_trans_begin(volume->volumes->repo, &trans);
     347                        if (rc != EOK)
     348                                goto error;
     349
     350                        rc = sif_node_append_child(trans,
     351                            volume->volumes->nvolumes, "volume", &nvolume);
     352                        if (rc != EOK)
     353                                goto error;
     354
     355                        rc = sif_node_set_attr(trans, nvolume, "label",
     356                            volume->label);
     357                        if (rc != EOK)
     358                                goto error;
     359
     360                        rc = sif_node_set_attr(trans, nvolume, "mountp",
     361                            volume->mountp);
     362                        if (rc != EOK)
     363                                goto error;
     364
     365                        rc = sif_trans_end(trans);
     366                        if (rc != EOK)
     367                                goto error;
     368
     369                        trans = NULL;
     370                        volume->nvolume = nvolume;
     371                } else {
     372                        /* Update volume node */
     373                        rc = sif_trans_begin(volume->volumes->repo, &trans);
     374                        if (rc != EOK)
     375                                goto error;
     376
     377                        rc = sif_node_set_attr(trans, volume->nvolume,
     378                            "mountp", volume->mountp);
     379                        if (rc != EOK)
     380                                goto error;
     381
     382                        rc = sif_trans_end(trans);
     383                        if (rc != EOK)
     384                                goto error;
     385
     386                        trans = NULL;
     387                }
     388        } else {
     389                /* Volume is now non-persistent */
     390                if (volume->nvolume != NULL) {
     391                        /* Delete volume node */
     392                        rc = sif_trans_begin(volume->volumes->repo, &trans);
     393                        if (rc != EOK)
     394                                goto error;
     395
     396                        sif_node_destroy(trans, volume->nvolume);
     397
     398                        rc = sif_trans_end(trans);
     399                        if (rc != EOK)
     400                                goto error;
     401
     402                        volume->nvolume = NULL;
     403                }
     404        }
     405
     406        free(old_mp);
    270407        return EOK;
     408error:
     409        free(mp);
     410        volume->mountp = old_mp;
     411
     412        if (trans != NULL)
     413                sif_trans_abort(trans);
     414        return rc;
     415}
     416
     417/** Load volumes from SIF repository.
     418 *
     419 * @param nvolumes Volumes node
     420 * @param volumes Volumes object
     421 *
     422 * @return EOK on success or error code
     423 */
     424static errno_t vol_volumes_load(sif_node_t *nvolumes, vol_volumes_t *volumes)
     425{
     426        sif_node_t *nvolume;
     427        vol_volume_t *volume = NULL;
     428        const char *label;
     429        const char *mountp;
     430        errno_t rc;
     431
     432        volumes->nvolumes = nvolumes;
     433
     434        nvolume = sif_node_first_child(nvolumes);
     435        while (nvolume != NULL) {
     436                if (str_cmp(sif_node_get_type(nvolume), "volume") != 0) {
     437                        rc = EIO;
     438                        goto error;
     439                }
     440
     441                volume = vol_volume_new();
     442                if (volume == NULL) {
     443                        rc = ENOMEM;
     444                        goto error;
     445                }
     446
     447                label = sif_node_get_attr(nvolume, "label");
     448                mountp = sif_node_get_attr(nvolume, "mountp");
     449
     450                if (label == NULL || mountp == NULL) {
     451                        rc = EIO;
     452                        goto error;
     453                }
     454
     455                free(volume->label);
     456                free(volume->mountp);
     457
     458                volume->label = str_dup(label);
     459                volume->mountp = str_dup(mountp);
     460
     461                volume->nvolume = nvolume;
     462                fibril_mutex_lock(&volumes->lock);
     463                vol_volume_add_locked(volumes, volume);
     464                fibril_mutex_unlock(&volumes->lock);
     465                nvolume = sif_node_next_child(nvolume);
     466        }
     467
     468        return EOK;
     469error:
     470        if (volume != NULL)
     471                vol_volume_delete(volume);
     472        return rc;
    271473}
    272474
  • uspace/srv/volsrv/volume.h

    r7ab7075f r1dcba91  
    4040#include "types/volume.h"
    4141
    42 extern errno_t vol_volumes_create(vol_volumes_t **);
     42extern errno_t vol_volumes_create(const char *, vol_volumes_t **);
    4343extern void vol_volumes_destroy(vol_volumes_t *);
    4444extern errno_t vol_volume_lookup_ref(vol_volumes_t *, const char *,
Note: See TracChangeset for help on using the changeset viewer.