Changeset 1dcba91 in mainline
- Timestamp:
- 2018-08-08T10:08:53Z (6 years ago)
- 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)
- Files:
-
- 1 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/Makefile
r7ab7075f r1dcba91 40 40 mkdir -p "$(DIST_PATH)/app/" 41 41 mkdir -p "$(DIST_PATH)/cfg/net/" 42 mkdir -p "$(DIST_PATH)/data/cfg/" 42 43 mkdir -p "$(DIST_PATH)/lib/" 43 44 mkdir -p "$(DIST_PATH)/loc/" … … 46 47 mkdir -p "$(DIST_PATH)/test/" 47 48 mkdir -p "$(DIST_PATH)/tmp/" 49 mkdir -p "$(DIST_PATH)/vol/" 48 50 for file in $(RD_SRVS) ; do \ 49 51 cp "$$file" "$(DIST_PATH)/srv/" ; \ -
uspace/app/contacts/contacts.c
r7ab7075f r1dcba91 78 78 } contact_action_t; 79 79 80 static errno_t contacts_ unmarshal(sif_node_t *, contacts_t *);80 static errno_t contacts_load(sif_node_t *, contacts_t *); 81 81 static contacts_entry_t *contacts_first(contacts_t *); 82 82 static contacts_entry_t *contacts_next(contacts_entry_t *); … … 150 150 } 151 151 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; 157 155 } 158 156 … … 171 169 } 172 170 173 /** Unmarshalcontact entries from SIF repository.171 /** Load contact entries from SIF repository. 174 172 * 175 173 * @param nentries Entries node 176 * @param contacts Contacts object to unmarshalto174 * @param contacts Contacts object to load to 177 175 * @return EOK on success or error code 178 176 */ 179 static errno_t contacts_ unmarshal(sif_node_t *nentries, contacts_t *contacts)177 static errno_t contacts_load(sif_node_t *nentries, contacts_t *contacts) 180 178 { 181 179 sif_node_t *nentry; -
uspace/lib/sif/private/sif.h
r7ab7075f r1dcba91 44 44 /** SIF session */ 45 45 struct sif_sess { 46 /** Backingfile */46 /** Repository file */ 47 47 FILE *f; 48 /** Repository file name */ 49 char *fname; 48 50 /** Root node */ 49 51 struct sif_node *root; -
uspace/lib/sif/src/sif.c
r7ab7075f r1dcba91 191 191 return ENOMEM; 192 192 193 sess->fname = str_dup(fname); 194 if (sess->fname == NULL) { 195 rc = ENOMEM; 196 goto error; 197 } 198 193 199 root = sif_node_new(NULL); 194 200 if (root == NULL) { … … 227 233 sif_trans_abort(trans); 228 234 sif_node_delete(root); 235 if (sess->fname != NULL) 236 free(sess->fname); 229 237 free(sess); 230 238 return rc; … … 249 257 return ENOMEM; 250 258 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"); 252 266 if (f == NULL) { 253 267 rc = EIO; … … 272 286 error: 273 287 sif_node_delete(root); 288 if (sess->fname != NULL) 289 free(sess->fname); 274 290 free(sess); 275 291 return rc; … … 290 306 } 291 307 308 if (sess->fname != NULL) 309 free(sess->fname); 310 free(sess); 292 311 return EOK; 293 312 } … … 394 413 errno_t rc; 395 414 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; 397 420 398 421 rc = sif_export_node(trans->sess->root, trans->sess->f); 399 422 if (rc != EOK) 400 423 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; 401 430 402 431 free(trans); -
uspace/srv/volsrv/Makefile
r7ab7075f r1dcba91 29 29 USPACE_PREFIX = ../.. 30 30 31 LIBS = label block31 LIBS = block label sif 32 32 33 33 BINARY = volsrv -
uspace/srv/volsrv/test/volume.c
r7ab7075f r1dcba91 29 29 #include <errno.h> 30 30 #include <pcut/pcut.h> 31 #include <stdio.h> 31 32 #include <str.h> 32 33 … … 41 42 { 42 43 vol_volumes_t *volumes; 44 char *namebuf; 45 char *fname; 43 46 errno_t rc; 47 int rv; 44 48 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); 46 56 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 47 57 48 58 vol_volumes_destroy(volumes); 59 rv = remove(fname); 60 PCUT_ASSERT_INT_EQUALS(0, rv); 61 free(fname); 49 62 } 50 63 … … 54 67 vol_volumes_t *volumes; 55 68 vol_volume_t *va, *vb, *va1; 69 char *namebuf; 70 char *fname; 56 71 errno_t rc; 72 int rv; 57 73 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); 59 81 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 60 82 … … 75 97 76 98 vol_volumes_destroy(volumes); 99 rv = remove(fname); 100 PCUT_ASSERT_INT_EQUALS(0, rv); 101 free(fname); 77 102 } 78 103 … … 82 107 vol_volumes_t *volumes; 83 108 vol_volume_t *va; 109 char *namebuf; 110 char *fname; 84 111 errno_t rc; 112 int rv; 85 113 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); 87 121 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 88 122 … … 108 142 109 143 vol_volumes_destroy(volumes); 144 rv = remove(fname); 145 PCUT_ASSERT_INT_EQUALS(0, rv); 146 free(fname); 110 147 } 111 148 -
uspace/srv/volsrv/types/volume.h
r7ab7075f r1dcba91 41 41 #include <atomic.h> 42 42 #include <fibril_synch.h> 43 #include <sif.h> 43 44 44 45 /** Volume */ … … 54 55 /** Mount point */ 55 56 char *mountp; 57 /** SIF node for this volume */ 58 sif_node_t *nvolume; 56 59 } vol_volume_t; 57 60 58 /** Partitions */61 /** Volumes */ 59 62 typedef struct vol_volumes { 60 63 /** Synchronize access to list of volumes */ … … 62 65 /** Volumes (list of vol_volume_t) */ 63 66 list_t volumes; 67 /** Cconfiguration repo session */ 68 sif_sess_t *repo; 69 /** Volumes SIF node */ 70 sif_node_t *nvolumes; 64 71 } vol_volumes_t; 65 72 -
uspace/srv/volsrv/volsrv.c
r7ab7075f r1dcba91 53 53 #define NAME "volsrv" 54 54 55 const char *vol_cfg_file = "/data/cfg/volsrv.sif"; 56 55 57 static void vol_client_conn(ipc_call_t *, void *); 56 58 … … 63 65 log_msg(LOG_DEFAULT, LVL_DEBUG, "vol_init()"); 64 66 65 rc = vol_volumes_create( &volumes);67 rc = vol_volumes_create(vol_cfg_file, &volumes); 66 68 if (rc != EOK) 67 69 goto error; -
uspace/srv/volsrv/volume.c
r7ab7075f r1dcba91 59 59 static errno_t vol_volume_lookup_ref_locked(vol_volumes_t *, const char *, 60 60 vol_volume_t **); 61 static errno_t vol_volumes_load(sif_node_t *, vol_volumes_t *); 61 62 62 63 /** Allocate new volume structure. … … 104 105 /** Create list of volumes. 105 106 * 107 * @param cfg_path Path to file containing configuration repository in SIF 106 108 * @param rvolumes Place to store pointer to list of volumes. 107 109 * @return EOK on success, ENOMEM if out of memory 108 110 */ 109 errno_t vol_volumes_create(vol_volumes_t **rvolumes) 111 errno_t vol_volumes_create(const char *cfg_path, 112 vol_volumes_t **rvolumes) 110 113 { 111 114 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; 112 120 113 121 volumes = calloc(1, sizeof(vol_volumes_t)); … … 118 126 list_initialize(&volumes->volumes); 119 127 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; 120 171 *rvolumes = volumes; 172 121 173 return EOK; 174 error: 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; 122 183 } 123 184 … … 195 256 return ENOMEM; 196 257 258 free(volume->label); 197 259 volume->label = str_dup(label); 260 261 if (volume->label == NULL) { 262 vol_volume_delete(volume); 263 return ENOMEM; 264 } 265 198 266 vol_volume_add_locked(volumes, volume); 199 267 … … 260 328 { 261 329 char *mp; 330 char *old_mp; 331 errno_t rc; 332 sif_trans_t *trans = NULL; 333 sif_node_t *nvolume; 262 334 263 335 mp = str_dup(mountp); … … 265 337 return ENOMEM; 266 338 267 free(volume->mountp);339 old_mp = volume->mountp; 268 340 volume->mountp = mp; 269 341 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); 270 407 return EOK; 408 error: 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 */ 424 static 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; 469 error: 470 if (volume != NULL) 471 vol_volume_delete(volume); 472 return rc; 271 473 } 272 474 -
uspace/srv/volsrv/volume.h
r7ab7075f r1dcba91 40 40 #include "types/volume.h" 41 41 42 extern errno_t vol_volumes_create( vol_volumes_t **);42 extern errno_t vol_volumes_create(const char *, vol_volumes_t **); 43 43 extern void vol_volumes_destroy(vol_volumes_t *); 44 44 extern errno_t vol_volume_lookup_ref(vol_volumes_t *, const char *,
Note:
See TracChangeset
for help on using the changeset viewer.