Changeset 8d74fdd in mainline


Ignore:
Timestamp:
2019-08-17T13:57:05Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
f92b315
Parents:
be07995
git-author:
Michal Koutný <xm.koutny+hos@…> (2016-01-27 00:01:13)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-17 13:57:05)
Message:

sysman: Shutdown operation as shutdown.tgt isolation

Since not all dependencies are captured by graph, sysman and taskman are
ignored when stopping servers, so that they can complete the shutdown
transition.

Conflicts:

boot/Makefile.common

Location:
uspace
Files:
3 added
14 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sysctl/main.c

    rbe07995 r8d74fdd  
    3939#include <str_error.h>
    4040#include <sysman/ctl.h>
     41#include <unistd.h>
    4142
    4243#define NAME "sysctl"
     
    141142}
    142143
     144static int shutdown(int argc, char *argv[])
     145{
     146        const int delay = 3;
     147        printf("Will shutdown in %i seconds...\n", delay);
     148        sleep(delay);
     149        printf("Shutdown now.\n");
     150
     151        int rc = sysman_shutdown();
     152        if (rc != EOK) {
     153                printf("Shutdown request failed: %s.\n", str_error(rc));
     154        }
     155        return rc;
     156}
     157
    143158command_t commands[] = {
    144159        { "list-units", 0, &list_units },
    145160        { "start",      1, &start },
    146161        { "stop",       1, &stop },
     162        { "shutdown",   0, &shutdown },
    147163        { 0 }
    148164};
  • uspace/lib/c/include/ipc/sysman.h

    rbe07995 r8d74fdd  
    5050        SYSMAN_CTL_GET_UNITS,
    5151        SYSMAN_CTL_UNIT_GET_NAME,
    52         SYSMAN_CTL_UNIT_GET_STATE
     52        SYSMAN_CTL_UNIT_GET_STATE,
     53        SYSMAN_CTL_SHUTDOWN
    5354} sysman_ipc_method_t;
    5455
  • uspace/lib/sysman/include/sysman/ctl.h

    rbe07995 r8d74fdd  
    4343int sysman_unit_get_name(unit_handle_t, char *, size_t);
    4444int sysman_unit_get_state(unit_handle_t, unit_state_t *);
     45
     46int sysman_shutdown(void);
    4547#endif
  • uspace/lib/sysman/src/ctl.c

    rbe07995 r8d74fdd  
    192192        return rc;
    193193}
     194
     195int sysman_shutdown(void)
     196{
     197        async_exch_t *exch = sysman_exchange_begin(SYSMAN_PORT_CTL);
     198        int rc = async_req_0_0(exch, SYSMAN_CTL_SHUTDOWN);
     199        sysman_exchange_end(exch);
     200
     201        return rc;
     202}
  • uspace/srv/sysman/Makefile

    rbe07995 r8d74fdd  
    4646        log.c \
    4747        repo.c \
     48        shutdown.c \
    4849        sm_task.c \
    4950        sysman.c \
  • uspace/srv/sysman/connection_ctl.c

    rbe07995 r8d74fdd  
    3636#include "connection_ctl.h"
    3737#include "job.h"
     38#include "job_closure.h"
    3839#include "log.h"
     40#include "shutdown.h"
    3941#include "sysman.h"
    4042
     
    114116
    115117        if (!(flags & IPC_FLAG_BLOCKING)) {
    116                 retval = sysman_run_job(unit, STATE_STARTED, NULL, NULL);
     118                retval = sysman_run_job(unit, STATE_STARTED, 0, NULL, NULL);
    117119                goto answer;
    118120        }
     
    123125                goto answer;
    124126        }
    125         retval = sysman_run_job(unit, STATE_STARTED, &answer_callback,
     127        retval = sysman_run_job(unit, STATE_STARTED, 0, &answer_callback,
    126128            iid_ptr);
    127129        if (retval != EOK) {
     
    154156
    155157        if (!(flags & IPC_FLAG_BLOCKING)) {
    156                 retval = sysman_run_job(unit, state, NULL, NULL);
     158                retval = sysman_run_job(unit, state, 0, NULL, NULL);
    157159                goto answer;
    158160        }
     
    163165                goto answer;
    164166        }
    165         retval = sysman_run_job(unit, state, &answer_callback,
     167        retval = sysman_run_job(unit, state, 0, &answer_callback,
    166168            iid_ptr);
    167169        if (retval != EOK) {
     
    278280}
    279281
     282static void sysman_shutdown(ipc_callid_t iid, ipc_call_t *icall)
     283{
     284        int retval;
     285        unit_t *u = repo_find_unit_by_name(TARGET_SHUTDOWN);
     286        if (u == NULL) {
     287                retval = ENOENT;
     288                goto finish;
     289        }
     290
     291        retval = sysman_run_job(u, STATE_STARTED, CLOSURE_ISOLATE,
     292            shutdown_cb, NULL);
     293
     294finish:
     295        async_answer_0(iid, retval);
     296}
     297
    280298void sysman_connection_ctl(ipc_callid_t iid, ipc_call_t *icall)
    281299{
     
    315333                        sysman_unit_get_state(callid, &call);
    316334                        break;
     335                case SYSMAN_CTL_SHUTDOWN:
     336                        sysman_shutdown(callid, &call);
     337                        break;
    317338                default:
    318339                        async_answer_0(callid, ENOENT);
  • uspace/srv/sysman/job_closure.c

    rbe07995 r8d74fdd  
    295295/** Creates job closure for given basic job
    296296 *
    297  * @note It is caller's responsibility to clean job_closure (event on error).
     297 * @note It is caller's responsibility to clean job_closure (even on error).
    298298 *
    299299 * @return EOK on success otherwise propagated error
  • uspace/srv/sysman/main.c

    rbe07995 r8d74fdd  
    3838#include <taskman.h>
    3939
    40 #include "repo.h"
    4140#include "connection_broker.h"
    4241#include "connection_ctl.h"
     
    4443#include "job_queue.h"
    4544#include "log.h"
     45#include "repo.h"
     46#include "sm_task.h"
    4647#include "sysman.h"
    47 #include "sm_task.h"
    4848#include "unit.h"
    4949
    5050#define NAME "sysman"
    51 
    52 #define INITRD_DEVICE       "bd/initrd"
    53 #define INITRD_MOUNT_POINT  "/"
    54 #define INITRD_CFG_PATH     "/cfg/sysman"
    55 
    56 #define TARGET_INIT     "initrd.tgt"
    57 #define TARGET_ROOTFS   "rootfs.tgt"
    58 #define TARGET_DEFAULT  "default.tgt"
    59 
    60 #define UNIT_MNT_INITRD "initrd.mnt"
    61 #define UNIT_CFG_INITRD "init.cfg"
    62 
    6351
    6452static const char *target_sequence[] = {
     
    195183        }
    196184
    197         int rc = sysman_run_job(tgt, STATE_STARTED, &sequence_job_handler,
     185        int rc = sysman_run_job(tgt, STATE_STARTED, 0, &sequence_job_handler,
    198186            target_name_ptr);
    199187
  • uspace/srv/sysman/sm_task.c

    rbe07995 r8d74fdd  
    106106         * name */
    107107
     108        /*
     109         * Temporary workaround to avoid killing ourselves during shutdown,
     110         * eventually should be captured by dependencies.
     111         */
     112        if (tid == task_get_id() || tid == 2 /*taskman*/) {
     113                CAST_SVC(u_svc)->critical = true;
     114        }
     115
    108116        repo_begin_update();
    109117        in_repo_update = true;
  • uspace/srv/sysman/sysman.c

    rbe07995 r8d74fdd  
    6565typedef struct {
    6666        job_t *job;
     67        int flags;
    6768        callback_handler_t callback;
    6869        void *callback_arg;
     
    205206 * If unit already has the same job assigned callback is moved to it.
    206207 *
    207  * @param[in]  callback  (optional) callback must explicitly delete reference
    208  *                       to job, void callback(void *job, void *callback_arg)
    209  *
    210  * return EBUSY  unit already has a job assigned of different type
    211  */
    212 int sysman_run_job(unit_t *unit, unit_state_t target_state,
     208 * @param[in]  flags        additional flags for job
     209 * @param[in]  callback     (optional) callback must explicitly delete reference
     210 *                          to job, void callback(void *job, void *callback_arg)
     211 * @param[in]  callback_arg
     212 *
     213 * @return EOK on successfully queued job
     214 */
     215int sysman_run_job(unit_t *unit, unit_state_t target_state, int flags,
    213216    callback_handler_t callback, void *callback_arg)
    214217{
     
    226229        /* Pass reference to job_args */
    227230        job_args->job = job;
     231        job_args->flags = flags;
    228232        job_args->callback = callback;
    229233        job_args->callback_arg = callback_arg;
     
    364368        job_args_t *job_args = data;
    365369        job_t *job = job_args->job;
     370        int flags = job_args->flags;
    366371        dyn_array_t job_closure;
    367372        dyn_array_initialize(&job_closure, job_t *);
     
    373378        free(job_args);
    374379
    375         int rc = job_create_closure(job, &job_closure, 0);
     380        int rc = job_create_closure(job, &job_closure, flags);
    376381        if (rc != EOK) {
    377382                sysman_log(LVL_ERROR, "Cannot create closure for job %p (%i)",
  • uspace/srv/sysman/sysman.h

    rbe07995 r8d74fdd  
    3030#define SYSMAN_SYSMAN_H
    3131
     32#define INITRD_DEVICE       "bd/initrd"
     33#define INITRD_MOUNT_POINT  "/"
     34#define INITRD_CFG_PATH     "/cfg/sysman"
     35
     36// TODO configurable
     37#define TARGET_INIT     "initrd.tgt"
     38#define TARGET_ROOTFS   "rootfs.tgt"
     39#define TARGET_DEFAULT  "default.tgt"
     40#define TARGET_SHUTDOWN "shutdown.tgt"
     41
     42#define UNIT_MNT_INITRD "initrd.mnt"
     43#define UNIT_CFG_INITRD "init.cfg"
     44
    3245#include "job.h"
    3346#include "unit.h"
     
    3851extern void sysman_events_init(void);
    3952extern int sysman_events_loop(void *);
    40 extern int sysman_run_job(unit_t *, unit_state_t, callback_handler_t, void *);
     53extern int sysman_run_job(unit_t *, unit_state_t, int, callback_handler_t, void *);
    4154
    4255
  • uspace/srv/sysman/test/job_queue.c

    rbe07995 r8d74fdd  
    8383        job_t *job = NULL;
    8484
    85         int rc = sysman_run_job(u, STATE_STARTED, &job_finished_cb,
     85        int rc = sysman_run_job(u, STATE_STARTED, 0, &job_finished_cb,
    8686            &job);
    8787        PCUT_ASSERT_INT_EQUALS(EOK, rc);
     
    102102        job_t *job = NULL;
    103103
    104         int rc = sysman_run_job(u, STATE_STARTED, &job_finished_cb, &job);
     104        int rc = sysman_run_job(u, STATE_STARTED, 0, &job_finished_cb, &job);
    105105        PCUT_ASSERT_INT_EQUALS(EOK, rc);
    106106
     
    142142        /* Run test */
    143143        job_t *job = NULL;
    144         int rc = sysman_run_job(s1, STATE_STARTED, &job_finished_cb, &job);
     144        int rc = sysman_run_job(s1, STATE_STARTED, 0, &job_finished_cb, &job);
    145145        PCUT_ASSERT_INT_EQUALS(EOK, rc);
    146146
     
    163163        /* Create and start first job */
    164164        job_t *j0 = NULL;
    165         int rc = sysman_run_job(s0, STATE_STARTED, &job_finished_cb, &j0);
     165        int rc = sysman_run_job(s0, STATE_STARTED, 0, &job_finished_cb, &j0);
    166166        PCUT_ASSERT_INT_EQUALS(EOK, rc);
    167167
     
    176176         */
    177177        job_t *j1 = NULL;
    178         rc = sysman_run_job(s0, STATE_STARTED, &job_finished_cb, &j1);
     178        rc = sysman_run_job(s0, STATE_STARTED, 0, &job_finished_cb, &j1);
    179179        PCUT_ASSERT_INT_EQUALS(EOK, rc);
    180180
  • uspace/srv/sysman/units/unit_svc.c

    rbe07995 r8d74fdd  
    120120        assert(unit->state == STATE_STARTED);
    121121
     122        /*
     123         * Ugly trick -- critical service is running despite being stopped
     124         * circumvent killing ourselves during shutdown (TODO dependencies).
     125         */
     126        if (u_svc->critical) {
     127                unit->state = STATE_STOPPED;
     128                return EOK;
     129        }
     130
    122131        int rc = task_kill(u_svc->main_task_id);
    123132
  • uspace/srv/sysman/units/unit_svc.h

    rbe07995 r8d74fdd  
    4343
    4444        bool anonymous;
     45
     46        /** Service can't be stopped, temporary workaround for shutdown */
     47        bool critical;
    4548} unit_svc_t;
    4649
Note: See TracChangeset for help on using the changeset viewer.