Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/system/system.c

    rad9e225 r77a0119  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * Copyright (c) 2005 Martin Decky
    44 * All rights reserved.
     
    3535 */
    3636
     37#include <devman.h>
    3738#include <fibril.h>
    3839#include <futil.h>
     
    4849#include <str.h>
    4950#include <loc.h>
     51#include <shutdown.h>
    5052#include <str_error.h>
    5153#include <config.h>
     
    8486
    8587static void system_srv_conn(ipc_call_t *, void *);
    86 static errno_t system_srv_shutdown(void *);
     88static errno_t system_srv_poweroff(void *);
     89static errno_t system_srv_restart(void *);
    8790
    8891system_ops_t system_srv_ops = {
    89         .shutdown = system_srv_shutdown
     92        .poweroff = system_srv_poweroff,
     93        .restart = system_srv_restart
    9094};
    9195
     
    382386                printf("%s: System volume is configured.\n", NAME);
    383387
    384                 /* Wait until system volume is mounted */
     388                /* Verify that system volume is mounted */
    385389                sv_mounted = false;
    386390
    387                 while (true) {
    388                         rc = vol_get_parts(vol, &part_ids, &nparts);
     391                rc = vol_get_parts(vol, &part_ids, &nparts);
     392                if (rc != EOK) {
     393                        printf("Error getting list of volumes.\n");
     394                        goto error;
     395                }
     396
     397                for (i = 0; i < nparts; i++) {
     398                        rc = vol_part_info(vol, part_ids[i], &pinfo);
    389399                        if (rc != EOK) {
    390                                 printf("Error getting list of volumes.\n");
     400                                printf("Error getting partition "
     401                                    "information.\n");
     402                                rc = EIO;
    391403                                goto error;
    392404                        }
    393405
    394                         for (i = 0; i < nparts; i++) {
    395                                 rc = vol_part_info(vol, part_ids[i], &pinfo);
    396                                 if (rc != EOK) {
    397                                         printf("Error getting partition "
    398                                             "information.\n");
    399                                         rc = EIO;
    400                                         goto error;
    401                                 }
    402 
    403                                 if (str_cmp(pinfo.cur_mp, "/w") == 0) {
    404                                         sv_mounted = true;
    405                                         break;
    406                                 }
     406                        if (str_cmp(pinfo.cur_mp, "/w") == 0) {
     407                                sv_mounted = true;
     408                                break;
    407409                        }
    408 
    409                         if (sv_mounted)
    410                                 break;
    411 
    412                         free(part_ids);
    413                         part_ids = NULL;
    414 
    415                         fibril_sleep(1);
    416                         printf("Sleeping(1) for system volume.\n");
    417                 }
     410                }
     411
     412                if (sv_mounted == false) {
     413                        printf("System volume not found.\n");
     414                        rc = EIO;
     415                        goto error;
     416                }
     417
     418                free(part_ids);
     419                part_ids = NULL;
     420
    418421        }
    419422
     
    520523        /* Eject all volumes. */
    521524
     525        log_msg(LOG_DEFAULT, LVL_NOTE, "Ejecting volumes.");
     526
    522527        rc = vol_create(&vol);
    523528        if (rc != EOK) {
     
    534539
    535540        for (i = 0; i < nparts; i++) {
    536                 rc = vol_part_eject(vol, part_ids[i]);
     541                rc = vol_part_eject(vol, part_ids[i], vef_none);
    537542                if (rc != EOK) {
    538543                        log_msg(LOG_DEFAULT, LVL_ERROR, "Error ejecting "
     
    544549        free(part_ids);
    545550        vol_destroy(vol);
     551
    546552        return EOK;
    547553error:
     
    610616}
    611617
    612 /** System shutdown request.
     618/** System poweroff request.
    613619 *
    614620 * @param arg Argument (sys_srv_t *)
    615621 */
    616 static errno_t system_srv_shutdown(void *arg)
     622static errno_t system_srv_poweroff(void *arg)
    617623{
    618624        sys_srv_t *syssrv = (sys_srv_t *)arg;
    619625        errno_t rc;
    620626
    621         log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_shutdown");
     627        log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_poweroff");
    622628
    623629        rc = system_sys_shutdown();
    624630        if (rc != EOK) {
    625                 log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_shutdown failed");
     631                log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_poweroff failed");
    626632                system_srv_shutdown_failed(&syssrv->srv);
    627633        }
    628634
    629         log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_shutdown complete");
     635        log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_poweroff complete");
     636        system_srv_shutdown_complete(&syssrv->srv);
     637        return EOK;
     638}
     639
     640/** System restart request.
     641 *
     642 * @param arg Argument (sys_srv_t *)
     643 */
     644static errno_t system_srv_restart(void *arg)
     645{
     646        sys_srv_t *syssrv = (sys_srv_t *)arg;
     647        errno_t rc;
     648
     649        log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_restart");
     650
     651        rc = system_sys_shutdown();
     652        if (rc != EOK) {
     653                log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_restart failed");
     654                system_srv_shutdown_failed(&syssrv->srv);
     655        }
     656
     657        /* Quiesce the device tree. */
     658
     659        log_msg(LOG_DEFAULT, LVL_NOTE, "Quiescing devices.");
     660
     661        rc = devman_quiesce_devices("/hw");
     662        if (rc != EOK) {
     663                log_msg(LOG_DEFAULT, LVL_ERROR,
     664                    "Failed to quiesce device tree.");
     665                return rc;
     666        }
     667
     668        sys_reboot();
     669
     670        log_msg(LOG_DEFAULT, LVL_NOTE, "system_srv_restart complete");
    630671        system_srv_shutdown_complete(&syssrv->srv);
    631672        return EOK;
Note: See TracChangeset for help on using the changeset viewer.