Changeset bb154c6 in mainline for uspace/srv/sysman/units/unit_mnt.c


Ignore:
Timestamp:
2019-08-03T08:15:25Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
09a8006
Parents:
6006f35
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-04-15 15:14:58)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-03 08:15:25)
Message:

Add skeleton for configuration files loading

  • Create content of /cfg directory,
  • create sample configuration file,
  • refactored polymorphism.

Conflicts:

boot/Makefile

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/sysman/units/unit_mnt.c

    r6006f35 rbb154c6  
    77#include "log.h"
    88#include "unit.h"
    9 #include "unit_mnt.h"
     9
     10static const char *section_name = "Mount";
     11
     12static config_item_t unit_configuration[] = {
     13        {"What",  &config_parse_string, offsetof(unit_mnt_t, device),     NULL},
     14        {"Where", &config_parse_string, offsetof(unit_mnt_t, mountpoint), NULL},
     15        {"Type",  &config_parse_string, offsetof(unit_mnt_t, type),       NULL},
     16        CONFIGURATION_ITEM_SENTINEL
     17};
    1018
    1119static void unit_mnt_init(unit_t *unit)
    1220{
    13         assert(unit->data.mnt.type == NULL);
    14         assert(unit->data.mnt.mountpoint == NULL);
    15         assert(unit->data.mnt.device == NULL);
     21        unit_mnt_t *u_mnt = CAST_MNT(unit);
     22        assert(u_mnt);
     23
     24        u_mnt->type = NULL;
     25        u_mnt->mountpoint = NULL;
     26        u_mnt->device = NULL;
     27}
     28
     29static void unit_mnt_destroy(unit_t *unit)
     30{
     31        assert(unit->type == UNIT_MOUNT);
     32        unit_mnt_t *u_mnt = CAST_MNT(unit);
     33
     34        sysman_log(LVL_DEBUG2, "%s, %p, %p, %p", __func__,
     35            u_mnt->type, u_mnt->mountpoint, u_mnt->device);
     36        free(u_mnt->type);
     37        free(u_mnt->mountpoint);
     38        free(u_mnt->device);
     39}
     40
     41static int unit_mnt_load(unit_t *unit, ini_configuration_t *ini_conf,
     42    text_parse_t *text_parse)
     43{
     44        unit_mnt_t *u_mnt = CAST_MNT(unit);
     45        assert(u_mnt);
     46
     47        ini_section_t *section = ini_get_section(ini_conf, section_name);
     48        if (section == NULL) {
     49                sysman_log(LVL_ERROR,
     50                    "Expected section '%s' in configuration of unit '%s'",
     51                    section_name, unit_name(unit));
     52                return ENOENT;
     53        }
     54
     55        return config_load_ini_section(unit_configuration, section, u_mnt,
     56            text_parse);
    1657}
    1758
    1859static int unit_mnt_start(unit_t *unit)
    1960{
     61        unit_mnt_t *u_mnt = CAST_MNT(unit);
     62        assert(u_mnt);
     63
    2064        fibril_mutex_lock(&unit->state_mtx);
    2165       
     
    2872
    2973
    30         unit_mnt_t *data = &unit->data.mnt;
    31 
    3274        // TODO use other mount parameters
    33         int rc = mount(data->type, data->mountpoint, data->device, "",
     75        int rc = mount(u_mnt->type, u_mnt->mountpoint, u_mnt->device, "",
    3476            IPC_FLAG_BLOCKING, 0);
    3577
    3678        if (rc == EOK) {
    37                 sysman_log(LVL_NOTE, "Mount (%p) mounted", unit);
     79                sysman_log(LVL_NOTE, "Mount ('%s') mounted", unit_name(unit));
    3880                unit_set_state(unit, STATE_STARTED);
    3981        } else {
    40                 sysman_log(LVL_ERROR, "Mount (%p) failed (%i)", unit, rc);
     82                sysman_log(LVL_ERROR, "Mount ('%s') failed (%i)",
     83                    unit_name(unit), rc);
    4184                unit_set_state(unit, STATE_FAILED);
    4285        }
     
    4588}
    4689
    47 static void unit_mnt_destroy(unit_t *unit)
    48 {
    49         free(unit->data.mnt.type);
    50         free(unit->data.mnt.mountpoint);
    51         free(unit->data.mnt.device);
    52 }
     90DEFINE_UNIT_VMT(unit_mnt)
    5391
    54 
    55 DEFINE_UNIT_OPS(unit_mnt)
    56 
Note: See TracChangeset for help on using the changeset viewer.