Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Oct 2024 08:40:36 +0200
From:      Stephane Rochoy <stephane.rochoy@stormshield.eu>
To:        Warner Losh <imp@bsdimp.com>
Cc:        <freebsd-hackers@freebsd.org>
Subject:   Re: swapon vs GEOM labels
Message-ID:  <86plnsr4d9.fsf@cthulhu.stephaner.labo.int>
In-Reply-To: <CANCZdfrk0tn68a0N89odyke%2BDDxgFqZOj41fsE=-7ehb2V8w0A@mail.gmail.com>
References:  <86ttd5rdze.fsf@cthulhu.stephaner.labo.int> <CANCZdfrk0tn68a0N89odyke%2BDDxgFqZOj41fsE=-7ehb2V8w0A@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

Warner Losh <imp@bsdimp.com> writes:

> On Mon, Oct 21, 2024 at 3:40=E2=80=AFAM Stephane Rochoy=20
> <stephane.rochoy@stormshield.eu> wrote:
>
>  Hi Hackers,
>
>  I'm playing with glabel(8) and swapon(8) but found a behavior=20
>  that
>  is somewhat puzzling.
>
>  I boot main (b88df1e893c4) with an USB memstick plugged. The
>  memstick is da0 and hold a freebsd-swap partition, da0p1. This
>  partition was given the `swap` label using `glabel label`=20
>  (i.e.,
>  an automatic label, stored somewhere into da0p1, AFAIK).
>
>    # glabel status
>          Name  Status  Components
>    label/swap     N/A  da0p1
>
>  Then I give the whole device the `usbmemstick` label using=20
>  `glabel
>  create` (i.e., a manual label, not stored anywhere).
>
>    # glabel create usbmemstick da0
>    # glabel status
>                Name  Status  Components
>          label/swap     N/A  da0p1
>    label/usbmemstick    N/A  da0
>
>  What puzzle me is what happen when I enable swap:
>
>    # sysctl vm.nswapdev
>    vm.nswapdev: 0
>    # swapctl -l
>    Device:      1024-blocks     Used:
>    # dumpon -l
>    /dev/null
>    # swapon /dev/label/usbmemstickp1
>    # glabel status
>                Name  Status  Components
>    label/usbmemstick    N/A  da0
>    # swapoff /dev/label/usbmemstickp1
>    # glabel status
>                Name  Status  Components
>    label/usbmemstick    N/A  da0
>          label/swap     N/A  label/usbmemstickp1
>
>  While swap is enabled, the `swap` label is no longer available.=20
>  It
>  comes back when swap is disabled.
>
>  Note that I also tried to enable swap using the automatic label
>  (i.e., `swap`). In such a case this is the `usbmemstick` label
>  that vanish. And the label is even not restored on `swapoff`.
>
>  Is it the expected behavior? Am I doing something wrong?
>
> This both makes sense to me, and seems wrong to me. When things
> are nested like this, it kinda makes sense that
> label/usbmemstickp1 shows up. geom doesn't enumerate everything
> and this seems to be a bit of an artifact. I'd expect both
> label/usbmemstickp1 and label/swap to be there. geom does odd
> things with devices that are open to keep others from opening
> them, and this may just be an artifact of this kinda weird
> behavior.

Well, I have to admit I'm a bit disappointed by the fact labels
don't completely mimic devices.

What I'm trying to achieve is to provide some sort of hardware
abstraction. I wrote a command that is responsible for probing
hardware and expose the fact that, e.g., an USB memstick is
available, a read/write SD card is inserted, etc=E2=80=A6

My first attempt was to use symlinks in /dev/. The problem with
this approach is that GEOM don't seems to dereference them. For
example, if I have /dev/sdcard =E2=86=92 /dev/da0, I cannot do things like=
=20
`geom
disk list sdcard`. IOW, the GEOM API is defeated by symlinks.

That's why I'm playing with labels.

If symlinks and labels are not well suited for that, do you know
of some alternative I could look at?

Regards,
--
St=C3=A9phane Rochoy
O: Stormshield



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86plnsr4d9.fsf>