From f44119a0e840985c482a7b58fb33d044c65dc052 Mon Sep 17 00:00:00 2001 From: unknown author <cooker@mandrivalinux.org> Date: Thu, 13 Nov 2008 15:12:56 +0000 Subject: [PATCH 34/35] waitdev --- mkinitrd | 63 ++++++++++++++++++++++++++++++++--------------------- nash/devtree.c | 18 ++++++++++++++- nash/nash.c | 36 +++++++++++++++++++++++++++--- nash/vitals.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- nash/waitdev.c | 2 - 5 files changed, 152 insertions(+), 33 deletions(-) diff --git a/mkinitrd b/mkinitrd index ff2c444..c458faf 100755 --- a/mkinitrd +++ b/mkinitrd @@ -61,10 +61,13 @@ MODULES="" GRAPHICSMODS="" PREMODS="" DMDEVS="" +DMDEVICES="" ncryptodevs=0 ncryptoparts=0 ncryptolvs=0 ncryptoraids=0 +raiddevices="" +raiddevs="" root="" NET_LIST="" @@ -93,6 +96,7 @@ PRESCSIMODS="" fstab="/etc/fstab" vg_list="" +vg_devs="" net_list="$NET_LIST" DEFAULT_DSDT_FILES="/boot/dsdt.aml /boot/DSDT.aml" @@ -623,6 +627,7 @@ handleraid() { esac done findstoragedriver $devs + raiddevs="$raiddevs $devs" if [ "$start" = 1 ]; then raiddevices="$raiddevices $1" fi @@ -662,7 +667,11 @@ handlelvordev() { *" $vg "*) ;; *) vg_list="$vg_list $vg" for device in $(vgdisplay $vg) ; do - findstoragedriver ${device##/dev/} + device=${device##/dev/} + if [[ ! "$device" =~ ^md[0-9]+ && ! "$device" =~ ^(dm-|mapper/) ]]; then + vg_devs="$vg_devs $device" + fi + findstoragedriver "$device" done [ -z "$nolvm" ] && find_base_dm_mods ;; @@ -670,6 +679,7 @@ handlelvordev() { else findstoragedriver ${1##/dev/} fi + vg_devs=$(echo $vg_devs | tr " " "\n" | sort -u) } handlenetdev() { @@ -1214,7 +1224,10 @@ if [ -n "$testdm" \ -a -e /dev/mapper/control ]; then dmout=$(/sbin/dmsetup ls 2>/dev/null) if [ "$dmout" != "No devices found" -a "$dmout" != "" ]; then - RAIDS=$(/sbin/dmraid -s -craidname 2>/dev/null | grep -vi "no raid disks") + RAIDS=$(/sbin/dmraid -s -craidname 2>/dev/null | grep -vi "no raid disks") + if [ -n "$RAIDS" ]; then + DMDEVICES=$(/sbin/dmraid -ay -t --ignorelocking | cut -d: -f2 | sed 's|[^/]*\(/[^ ]*\)[^/]*|\1 |g' | tr ' ' '\n' | grep -v /dev/mapper | sed -n 's|/dev/||p' | sort -u) + fi # I fucking hate shell. lineno=1 @@ -1235,7 +1248,7 @@ if [ -n "$testdm" \ echo TYPE=\"$TYPE\" echo TABLE=\"$TABLE\" done) - + case "$TYPE" in multipath|emc) # ugggh. We could try to fish the module name out, but it @@ -1250,6 +1263,10 @@ if [ -n "$testdm" \ for raid in $RAIDS ; do if [ "$raid" == "$NAME" ]; then dmname=$(resolve_dm_name $NAME) + if [ -z "$dmname" ]; then + echo "**** COULD NOT RESOLVE DM NAME $NAME ****" + dmname="$NAME" + fi DMDEVS="$DMDEVS $dmname" RAIDS=$(sed 's/ $NAME //' <<< "$RAIDS") break @@ -1517,16 +1534,6 @@ emitmodules() { emit "echo \"Loading $module module\"" emit "modprobe -q $module" - # Hack - we need a delay after loading usb-storage to give things - # time to settle down before we start looking a block devices - if [[ "$module" =~ usb[_-]storage ]] || [ "$module" = "ub" ]; then - if [ "$found_hcd_module" == "no" -a "$usb_mounted" == "prep" ]; then - usb_mounted=yes - emit "mount -t usbfs /proc/bus/usb /proc/bus/usb" - fi - emit "echo Waiting for driver initialization." - emit "stabilized /proc/bus/usb/devices" - fi # Firewire likes to change the subsystem name every 3 hours. :/ if [ "$module" = "sbp2" ]; then emit "echo Waiting for driver initialization." @@ -1554,9 +1561,6 @@ emitmodules() { EOF done fi - if [ "${module::5}" == "pata_" -o "$module" == "ata_piix" -o "$module" == "ahci" -o "${module::5}" == "sata_" -o "$module" == "ibmvscsic" ]; then - wait_for_scsi="yes" - fi done if [ "$wait_for_scsi" == "yes" ]; then emit "echo Waiting for driver initialization." @@ -1685,11 +1689,6 @@ emit "hotplug" emit "echo Creating block device nodes." emit "mkblkdevs" -if [ "$scsi_wait_scan" == "yes" ]; then - vecho "Adding module scsi_wait_scan" - installmodule scsi_wait_scan -fi - /sbin/depmod -a -b $MNTIMAGE $kernel if [ $? -ne 0 ]; then error "\"/sbin/depmod -a $kernel\" failed." @@ -1705,7 +1704,7 @@ loadDrivers EOF fi -if [ -z "$nolvm" -a -n "$vg_list" -o $ncryptodevs -ne 0 ]; then +if [ \( -z "$nolvm" -a -n "$vg_list" \) -o $ncryptodevs -ne 0 ]; then emit "echo Making device-mapper control node" emit "mkdmnod" fi @@ -1720,9 +1719,20 @@ fi emit_iscsi -if [ "$scsi_wait_scan" == "yes" ]; then - emit "modprobe scsi_wait_scan" - emit "rmmod scsi_wait_scan" +if [ -n "$DMDEVICES" -o -n "$raiddevs" -o \( -z "$nolvm" -a -n "$vg_list" \) ]; then + if [ -z "$nolvm" -a -n "$vg_list" ]; then + devices=$(echo $raiddevs $vg_devs $DMDEVICES | sort -u) + else + devices=$(echo $raiddevs $DMDEVICES | sort -u) + fi + for dev in $devices; do + emit "echo waiting for device $dev to appear (timeout 1min)" + emit "waitdev --timeout=60000000 /dev/${dev}" + done +else if [ $ncryptodevs -eq 0 ]; then + emit "echo waiting for root device $rootdev to appear (timeout 1min)" + emit "waitdev --timeout=60000000 --rootdev $rootdev" +fi fi # HACK: module loading + device creation isn't necessarily synchronous... @@ -1736,6 +1746,9 @@ emitcrypto() { #emit "echo Setting up disk encryption: $1" #emit "plymouth ask-for-password --command \"cryptsetup luksOpen $1 $2\"" + emit "echo waiting for encrypted device $1 to appear (timeout 1min)" + emit "waitdev --timeout=60000000 $1" + emit "mkblkdevs" emit "askpass \"Enter passphrase to unlock the disk $1 ($2): \" /sbin/cryptsetup -T 1 --key-file=- luksOpen $1 $2" } diff --git a/nash/devtree.c b/nash/devtree.c index 6ced12d..3ef9d6d 100644 --- a/nash/devtree.c +++ b/nash/devtree.c @@ -1455,6 +1455,7 @@ struct nash_dev_node *nash_dev_tree_find_device(nashContext *nc, char *device, LABEL, UUID, PATH, + DEVNO, } type = PATH; i = -1; @@ -1476,15 +1477,30 @@ struct nash_dev_node *nash_dev_tree_find_device(nashContext *nc, char *device, } else if (!strncasecmp(device, "uuid=", 5)) { type = UUID; target += 5; + } else if (device[0] != '/') { + type = DEVNO; } - if (type != PATH) { + if (type == DEVNO) { + int devno; + int n = sscanf(device, "%x", &devno); + if (n) { + dev_t ndev = makedev(-1,-1); + while (!adult && (child = nash_list_get(nc->devices->devs, ++i))) { + if (devno != ndev && devno == child->bdev->devno) { + adult = child; + break; + } + } + } + } else if (type != PATH) { while (!adult && (child = nash_list_get(nc->devices->fs_devs, ++i))) { if (nash_dev_node_vitals_has(nc, child, type == LABEL ? "label" : "unique_id", target)) adult = child; } + i = -1; while (!adult && (child = nash_list_get(nc->devices->devs, ++i))) { if (nash_dev_node_vitals_has(nc, child, diff --git a/nash/nash.c b/nash/nash.c index 2c4863a..cd24059 100644 --- a/nash/nash.c +++ b/nash/nash.c @@ -1515,12 +1515,18 @@ resumeCommand(char * cmd, char * end) while (*chptr && !isspace(*chptr)) chptr++; c = *chptr; *chptr = '\0'; + if (nashWaitForDevice(_nash_context, resume, 10000000) < 1) { + eprintf("Could not find resume device (%s)\n",resume); + } + resumedev = nashGetPathBySpec(_nash_context, resume); if (resumedev == NULL) { eprintf("Could not resolve resume device (%s)\n", resume); - } else if (access(resumedev, R_OK)) { - eprintf("Unable to access resume device (%s)\n", resumedev); - resumedev = NULL; + } else { + if (access(resumedev, R_OK)) { + eprintf("Unable to access resume device (%s)\n", resumedev); + resumedev = NULL; + } } *chptr = c; } else { @@ -3099,10 +3105,14 @@ static int waitdevCommand(char *cmd, char *end) { char *device = NULL; + char *root = NULL; long long timeout = -2; int rc = 0; + int use_rootdev = 0; + while (1) { + if (!(cmd = getArg(cmd, end, &device))) { eprintf("waitdev: block device name expected\n"); return 1; @@ -3124,6 +3134,8 @@ waitdevCommand(char *cmd, char *end) eprintf("waitdev: \"%s\": %m\n", to_str); return 1; } + } else if (!strncmp(device, "--rootdev", 9)) { + use_rootdev = 1; } else { break; } @@ -3137,8 +3149,24 @@ waitdevCommand(char *cmd, char *end) return 1; } + if (use_rootdev) { + root = getKernelArg("root"); + if (root) { + char c; + char *chptr; + chptr = root; + while (*chptr && !isspace(*chptr)) + chptr++; + c = *chptr; + *chptr = '\0'; + root = strdupa(root); + *chptr = c; + chptr = NULL; + } + } + rc = 1; - if (nashWaitForDevice(_nash_context, device, timeout) > 0) + if (nashWaitForDevice(_nash_context, use_rootdev && root ? root : device, timeout) > 0) rc = 0; return rc; diff --git a/nash/vitals.c b/nash/vitals.c index 1198750..0011348 100644 --- a/nash/vitals.c +++ b/nash/vitals.c @@ -547,6 +547,58 @@ int probe_bdevid(nashContext *nc, struct probe_info *pi, /* end DEV_TYPE_DM_MPATH probe */ /* begin DEV_TYPE_PARTITION probe */ +int probe_partitions(nashContext *nc, struct probe_info *pi, + struct nash_list *nodes, struct nash_bdev_vitals **vitalsp) +{ + struct bdevid_probe_priv priv = { .nc = nc }; + blkid_dev bdev = NULL; + blkid_tag_iterate titer; + struct nash_bdev_vitals *vitals; + struct nash_dev_node *node; + const char *type, *data; + + if (!(node = priv.node = nash_list_get(nodes, 0))) + return -1; + + if (!(vitals = priv.vitals = nash_bdev_vitals_alloc())) + return -1; + + bdev = blkid_get_dev(nc->cache, node->bdev->dev_path, BLKID_DEV_NORMAL); + if (!bdev) + return -1; + + titer = blkid_tag_iterate_begin(bdev); + while (blkid_tag_next(titer, &type, &data) >= 0) { + if (!strcmp(type, "LABEL")) { + vitals->type = DEV_TYPE_FS; + vitals->fs_label = strdup(data); + } + if (!strcmp(type, "UUID")) { + vitals->type = DEV_TYPE_FS; + vitals->unique_id = strdup(data); + } + if (!strcmp(type, "TYPE")) { + vitals->type = DEV_TYPE_FS; + vitals->fs_type = strdup(data); + } + } + blkid_tag_iterate_end(titer); + + if (vitals->fs_type == NULL) { + nash_vitals_decref(nc, vitals); + return -1; + } + + *vitalsp = nash_vitals_cache_insert(nc, vitals); + if (*vitalsp != vitals) { + if (*vitalsp) + nash_vitals_incref(*vitalsp); + nash_vitals_decref(nc, vitals); + priv.vitals = *vitalsp; + } + + return 0; +} /* end DEV_TYPE_PARTITION probe */ /* @@ -592,12 +644,13 @@ static struct probe_info probe_info[] = { .free_priv = probe_bdevid_destroy, .do_probe = probe_bdevid, }, -#if 0 + { .id = PROBE_PARTITION, .name = "partition", .do_probe = probe_partitions, }, +#if 0 /* XXX add probes for DM_MPATH, DM_RAID, MD_RAID, * LVM2_PV, LVM2_VG, and LVM2_LV */ @@ -767,6 +820,17 @@ struct nash_list *nash_vitals_probe(nashContext *nc, } } break; + case DEV_TYPE_PARTITION: + nash_list_add(nodes, node); + pi = get_probe_info(PROBE_PARTITION); + vitals = NULL; + if (pi->do_probe(nc, pi, nodes, &vitals) >= 0) { + if (vitals) { + nash_list_add(ret, vitals); + print_vitals(vitals); + } + } + break; default: case DEV_TYPE_NONE: /* this is here just for gcc's benefit. */ diff --git a/nash/waitdev.c b/nash/waitdev.c index 0262816..73f61e1 100644 --- a/nash/waitdev.c +++ b/nash/waitdev.c @@ -80,10 +80,8 @@ nashWaitForDevice(nashContext *nc, char *device, long long wait_usecs) rc = 0; if (node || (node = nash_dev_tree_find_device(nc, device, blktab))) { - if (nash_dev_tree_check_node_complete(nc, node) > 0) { rc = 1; break; - } } if (ret == 0) break; -- 1.6.2.2