← Back to team overview

cloud-init-dev team mailing list archive

Re: [Merge] ~pengpengs/cloud-init:fix/ds-identify-dscheck-OVF-is-cdrom-oversized into cloud-init:master

 

I've some suggestions on how we can get cdrom size without mounting.



Diff comments:

> diff --git a/tools/ds-identify b/tools/ds-identify
> index e16708f..12a36bb 100755
> --- a/tools/ds-identify
> +++ b/tools/ds-identify
> @@ -746,6 +747,32 @@ ovf_vmware_transport_guestinfo() {
>      return 0
>  }
>  
> +is_cdrom_oversized() {
> +    local dev="$1"
> +    local mountPath="${PATH_RUN_CI_CDROM}$dev"

I don't think we need to have a mount per device here.
If we determine that the current cdrom device "dev" 
indicates that we're on OVF, then we can leave it mounted.

If the cdrom does not indicate an OVF, we don't need to leave
it mounted.

is_cdrom_ovf is called once for each iso device.

> +    local ret=0 out=""
> +    # check if cdrom has been mounted, the result is different
> +    # between linux distroes. If not, create a directory under
> +    # /run/cloud-init/cdrom and then mount cdrom with it.
> +    out=$(cat /etc/mtab | grep $dev) || {
> +        [ -d "$mountPath" ] || mkdir --parents "$mountPath"
> +        mount "$dev" "$mountPath"
> +    }

if ! grep -q "$dev" /proc/mounts; then
    mkdir --parents "${PATH_RUN_CI_CDROM}"
    mount "$dev" "${PATH_RUN_CI_CDROM}"
fi

> +    # grep cdrom size with block-size set to 1K, consider cdrom
> +    # is oversized if result reaches 6 digit which means cdrom
> +    # size > 99999K
> +    out=$(df --block-size=1K "$dev" | grep --perl-regexp --only-matching "$dev\s+\d{6}")

We don't need to grep the size, instead calculate from sysfs:

local size_limit=$((100 * 1024 * 1024))  # we can put whatever in here
local dev_sectors=""; dev_size=""
read dev_sectors < /sys/class/block/`basename $dev`/size
dev_size=$(($dev_sectors * 512))
if [ $dev_size -gt $size_limit ]; then
    debug 1 "$dev is oversized ($dev_size > $size_limit)"
    return 0
fi

> +    ret=$?
> +    # check if the directory under /run/cloud-init/cdrom exists.
> +    # if yes, unmount and delete it
> +    [ -d "$mountPath" ] && umount "$mountPath" && rm -rf "${PATH_RUN_CI_CDROM}"
> +    if [ $ret -eq 0 ]; then
> +        debug 1 "$dev is oversized"
> +        return 0
> +    fi
> +    return 1

we can avoid the mount/unmount if we just read size from sysfs

> +}
> +
>  is_cdrom_ovf() {
>      local dev="$1" label="$2"
>      # skip devices that don't look like cdrom paths.


-- 
https://code.launchpad.net/~pengpengs/cloud-init/+git/cloud-init/+merge/368959
Your team cloud-init commiters is requested to review the proposed merge of ~pengpengs/cloud-init:fix/ds-identify-dscheck-OVF-is-cdrom-oversized into cloud-init:master.


References