]> git.ozlabs.org Git - petitboot/commitdiff
Merge remote-tracking branch 'sammj/master'
authorJeremy Kerr <jk@ozlabs.org>
Tue, 14 Apr 2015 05:36:38 +0000 (15:36 +1000)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 14 Apr 2015 05:36:38 +0000 (15:36 +1000)
discover/device-handler.c
discover/network.c
ui/ncurses/nc-add-url.c
ui/ncurses/nc-boot-editor.c
ui/ncurses/nc-config.c
ui/ncurses/nc-lang.c
ui/ncurses/nc-menu.c

index 5d9f98892eb792db789de351fb750bb95cd0e3f9..f0537134c1a3bc2a517f40b8cc385525940dfe0b 100644 (file)
@@ -1082,6 +1082,20 @@ static void device_handler_reinit_sources(struct device_handler *handler)
                        handler->dry_run);
 }
 
+static const char *fs_parameters(unsigned int rw_flags, const char *fstype)
+{
+       if ((rw_flags | MS_RDONLY) != MS_RDONLY)
+               return "";
+
+       /* Avoid writing back to the disk on journaled filesystems */
+       if (!strncmp(fstype, "ext4", strlen("ext4")))
+               return "norecovery";
+       if (!strncmp(fstype, "xfs", strlen("xfs")))
+               return "norecovery";
+
+       return "";
+}
+
 static bool check_existing_mount(struct discover_device *dev)
 {
        struct stat devstat, mntstat;
@@ -1155,6 +1169,13 @@ static int mount_device(struct discover_device *dev)
        if (!fstype)
                return 0;
 
+       /* ext3 treats the norecovery option as an error, so mount the device
+        * as an ext4 filesystem instead */
+       if (!strncmp(fstype, "ext3", strlen("ext3"))) {
+               pb_debug("Mounting ext3 filesystem as ext4\n");
+               fstype = talloc_asprintf(dev, "ext4");
+       }
+
        dev->mount_path = join_paths(dev, mount_base(),
                                        dev->device_path);
 
@@ -1167,7 +1188,8 @@ static int mount_device(struct discover_device *dev)
        pb_log("mounting device %s read-only\n", dev->device_path);
        errno = 0;
        rc = mount(dev->device_path, dev->mount_path, fstype,
-                       MS_RDONLY | MS_SILENT, "");
+                       MS_RDONLY | MS_SILENT,
+                       fs_parameters(MS_RDONLY, fstype));
        if (!rc) {
                dev->mounted = true;
                dev->mounted_rw = false;
@@ -1209,6 +1231,7 @@ static int umount_device(struct discover_device *dev)
 
 int device_request_write(struct discover_device *dev, bool *release)
 {
+       const char *fstype;
        int rc;
 
        *release = false;
@@ -1219,25 +1242,48 @@ int device_request_write(struct discover_device *dev, bool *release)
        if (dev->mounted_rw)
                return 0;
 
+       fstype = discover_device_get_param(dev, "ID_FS_TYPE");
+
        pb_log("remounting device %s read-write\n", dev->device_path);
-       rc = mount(dev->device_path, dev->mount_path, "",
-                       MS_REMOUNT | MS_SILENT, "");
-       if (rc)
+
+       rc = umount(dev->mount_path);
+       if (rc) {
+               pb_log("Failed to unmount %s\n", dev->mount_path);
                return -1;
+       }
+       rc = mount(dev->device_path, dev->mount_path, fstype,
+                       MS_SILENT,
+                       fs_parameters(MS_REMOUNT, fstype));
+       if (rc)
+               goto mount_ro;
 
        dev->mounted_rw = true;
        *release = true;
        return 0;
+
+mount_ro:
+       pb_log("Unable to remount device %s read-write\n", dev->device_path);
+       rc = mount(dev->device_path, dev->mount_path, fstype,
+                       MS_RDONLY | MS_SILENT,
+                       fs_parameters(MS_RDONLY, fstype));
+       if (rc)
+               pb_log("Unable to recover mount for %s\n", dev->device_path);
+       return -1;
 }
 
 void device_release_write(struct discover_device *dev, bool release)
 {
+       const char *fstype;
+
        if (!release)
                return;
 
+       fstype = discover_device_get_param(dev, "ID_FS_TYPE");
+
        pb_log("remounting device %s read-only\n", dev->device_path);
        mount(dev->device_path, dev->mount_path, "",
-                       MS_REMOUNT | MS_RDONLY | MS_SILENT, "");
+                       MS_REMOUNT | MS_RDONLY | MS_SILENT,
+                       fs_parameters(MS_RDONLY, fstype));
        dev->mounted_rw = false;
 }
 
index 3946694615fd4d931352610fd8abbafafd8a8264..0dad087bb4199a3d2ed15510bad1f0b43cc1f1ab 100644 (file)
@@ -510,6 +510,15 @@ static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg)
                add_interface(network, interface);
        }
 
+       /* A repeated RTM_NEWLINK can represent an interface name change */
+       if (strncmp(interface->name, ifname, IFNAMSIZ)) {
+               pb_debug("ifname update: %s -> %s\n", interface->name, ifname);
+               strncpy(interface->name, ifname, sizeof(interface->name) - 1);
+               talloc_free(interface->dev->device->id);
+               interface->dev->device->id =
+                       talloc_strdup(interface->dev->device, ifname);
+       }
+
        /* notify the sysinfo code about changes to this interface */
        if (strcmp(interface->name, "lo"))
                system_info_register_interface(
index 386d813264af64e25a257b3a30b5db33f2061744..cf55b03a104df725fcb9c2207c816cda87df1b5a 100644 (file)
@@ -43,6 +43,7 @@ struct add_url_screen {
 
        bool                    exit;
        bool                    show_help;
+       bool                    need_redraw;
        void                    (*on_exit)(struct cui *);
 
        int                     label_x;
@@ -93,6 +94,7 @@ static void add_url_screen_process_key(struct nc_scr *scr, int key)
 
        } else if (screen->show_help) {
                screen->show_help = false;
+               screen->need_redraw = true;
                cui_show_help(screen->cui, _("Retrieve Config"),
                        &add_url_help_text);
 
@@ -106,7 +108,10 @@ static int add_url_screen_post(struct nc_scr *scr)
        struct add_url_screen *screen = add_url_screen_from_scr(scr);
        widgetset_post(screen->widgetset);
        nc_scr_frame_draw(scr);
-       redrawwin(scr->main_ncw);
+       if (screen->need_redraw) {
+               redrawwin(scr->main_ncw);
+               screen->need_redraw = false;
+       }
        wrefresh(screen->scr.main_ncw);
        return 0;
 }
@@ -224,6 +229,7 @@ struct add_url_screen *add_url_screen_init(struct cui *cui,
        screen->on_exit = on_exit;
        screen->label_x = 2;
        screen->field_x = 25;
+       screen->need_redraw = false;
 
        nc_scr_init(&screen->scr, pb_add_url_screen_sig, 0,
                cui, add_url_screen_process_key,
index 409e638e21eafd39e55aa183b5213d7eeff7373f..274bd9d2fa1b4df079eb050c10524bc46abad5b1 100644 (file)
@@ -44,6 +44,7 @@ struct boot_editor {
        void                    (*on_exit)(struct cui *cui,
                                        struct pmenu_item *item,
                                        struct pb_boot_data *bd);
+       bool                    need_redraw;
 
        int                     label_x;
        int                     field_x;
@@ -111,7 +112,10 @@ static int boot_editor_post(struct nc_scr *scr)
        struct boot_editor *boot_editor = boot_editor_from_scr(scr);
        widgetset_post(boot_editor->widgetset);
        nc_scr_frame_draw(scr);
-       redrawwin(scr->main_ncw);
+       if (boot_editor->need_redraw) {
+               redrawwin(scr->main_ncw);
+               boot_editor->need_redraw = false;
+       }
        wrefresh(boot_editor->scr.main_ncw);
        pad_refresh(boot_editor);
        return 0;
@@ -173,6 +177,10 @@ static struct pb_boot_data *boot_editor_prepare_data(
 
        s = widget_textbox_get_value(boot_editor->widgets.image_f);
        bd->image = conditional_prefix(bd, prefix, s);
+       if (!bd->image) {
+               talloc_free(bd);
+               return NULL;
+       }
 
        s = widget_textbox_get_value(boot_editor->widgets.initrd_f);
        bd->initrd = conditional_prefix(bd, prefix, s);
@@ -216,12 +224,18 @@ static void boot_editor_process_key(struct nc_scr *scr, int key)
        case STATE_SAVE:
                item = boot_editor->item;
                bd = boot_editor_prepare_data(boot_editor);
+               if (!bd) {
+                       /* Incomplete entry */
+                       boot_editor->state = STATE_EDIT;
+                       break;
+               }
                /* fall through */
        case STATE_CANCEL:
                boot_editor->on_exit(boot_editor->cui, item, bd);
                break;
        case STATE_HELP:
                boot_editor->state = STATE_EDIT;
+               boot_editor->need_redraw = true;
                cui_show_help(boot_editor->cui, _("Boot Option Editor"),
                                &boot_editor_help_text);
                break;
@@ -559,6 +573,7 @@ struct boot_editor *boot_editor_init(struct cui *cui,
        boot_editor->item = item;
        boot_editor->on_exit = on_exit;
        boot_editor->state = STATE_EDIT;
+       boot_editor->need_redraw = false;
 
        int ncols1 = strncols(_("Device tree:"));
        int ncols2 = strncols(_("Boot arguments:"));
index 17cc380172cb15394fb0b3bb73b84cfd270d8d4d..c45df34e9afce17f5d641206bade8923e3bff252 100644 (file)
@@ -57,6 +57,7 @@ struct config_screen {
 
        bool                    exit;
        bool                    show_help;
+       bool                    need_redraw;
        void                    (*on_exit)(struct cui *);
 
        int                     scroll_y;
@@ -146,6 +147,7 @@ static void config_screen_process_key(struct nc_scr *scr, int key)
 
        } else if (screen->show_help) {
                screen->show_help = false;
+               screen->need_redraw = true;
                cui_show_help(screen->cui, _("System Configuration"),
                                &config_help_text);
 
@@ -165,7 +167,10 @@ static int config_screen_post(struct nc_scr *scr)
        struct config_screen *screen = config_screen_from_scr(scr);
        widgetset_post(screen->widgetset);
        nc_scr_frame_draw(scr);
-       redrawwin(scr->main_ncw);
+       if (screen->need_redraw) {
+               redrawwin(scr->main_ncw);
+               screen->need_redraw = false;
+       }
        wrefresh(screen->scr.main_ncw);
        pad_refresh(screen);
        return 0;
@@ -859,6 +864,7 @@ struct config_screen *config_screen_init(struct cui *cui,
 
        screen->cui = cui;
        screen->on_exit = on_exit;
+       screen->need_redraw = false;
        screen->label_x = 2;
        screen->field_x = 17;
 
index 0422ebba7531e4a2cd7db87b5319c708f7084b99..0b871566aa83fbeda61e02da393f6fb204be36ed 100644 (file)
@@ -131,7 +131,6 @@ static int lang_screen_post(struct nc_scr *scr)
        struct lang_screen *screen = lang_screen_from_scr(scr);
        widgetset_post(screen->widgetset);
        nc_scr_frame_draw(scr);
-       redrawwin(scr->main_ncw);
        wrefresh(screen->scr.main_ncw);
        pad_refresh(screen);
        return 0;
index 7ff2468cb1c47d3b1caae9cf3180523ad920f939..b8f9a35e0cddcd7ac16bbd330e73104ee8a0a3e4 100644 (file)
@@ -62,7 +62,6 @@ static int pmenu_post(struct nc_scr *scr)
        result = post_menu(menu->ncm);
 
        nc_scr_frame_draw(scr);
-       redrawwin(menu->scr.main_ncw);
        wrefresh(menu->scr.main_ncw);
 
        return result;