Re: how do I mount a read-only filesystem from the "root device" prompt?

2021-04-05 Thread Greg A. Woods
At Mon, 5 Apr 2021 07:04:32 - (UTC), mlel...@serpens.de (Michael van Elst) 
wrote:
Subject: Re: how do I mount a read-only filesystem from the "root device" 
prompt?
>
> Someone would need to write code to "upgrade" vnodes. I doubt that's
> trivial.

Indeed -- I've underestimated the complexity of such low-level changes
in the past -- they can snowball out of control!

> Fortunately it is not necessary. If the parent device is read-only,
> no "upgrade" will help to make it read-write. So you open read-write
> or fail back to read-only when necessary. An attempt to open a wedge
> read-write on a read-only opened parent device then has to fail.

Yes, this makes sense.

> I'm testing a patch for that...

Excellent!  Thank you very much!

--
Greg A. Woods 

Kelowna, BC +1 250 762-7675   RoboHack 
Planix, Inc.  Avoncote Farms 


pgpXg3AxNRSEV.pgp
Description: OpenPGP Digital Signature


Re: how do I mount a read-only filesystem from the "root device" prompt?

2021-04-05 Thread Manuel Bouyer
On Sun, Apr 04, 2021 at 03:13:35PM -0700, Greg A. Woods wrote:
> I would think it's not just CDs and hypervisor-provided virtual devices
> that can have multiple partitions, use wedges, and yet be read-only.
> 
> Are not a wide variety of removable storage devices also capable of
> being made "read-only" at the hardware level?

At last some SCSI devices had a pin to make then read-only. I used this
to build ssh gateways in the past ...

-- 
Manuel Bouyer 
 NetBSD: 26 ans d'experience feront toujours la difference
--


Re: how do I mount a read-only filesystem from the "root device" prompt?

2021-04-05 Thread Michael van Elst
wo...@planix.ca ("Greg A. Woods") writes:

>Given the layers of devices and code involved, perhaps it might be
>possible to just honour the original mode requested by the code opening
>the first partition to mount a filesystem, and then to upgrade the vnode
>to write mode if/when that mount is upgraded to write mode or another rw
>mount is attempted on another partition on the same device?

Someone would need to write code to "upgrade" vnodes. I doubt that's
trivial. Fortunately it is not necessary. If the parent device is read-only,
no "upgrade" will help to make it read-write. So you open read-write
or fail back to read-only when necessary. An attempt to open a wedge
read-write on a read-only opened parent device then has to fail.

I'm testing a patch for that...



Re: how do I mount a read-only filesystem from the "root device" prompt?

2021-04-04 Thread Greg A. Woods
At Sun, 4 Apr 2021 01:19:44 -0700, John Nemeth  wrote:
Subject: Re: how do I mount a read-only filesystem from the "root device" 
prompt?
>
>  Given that it is possible to have partitions on CDs, which is
> common on Suns, but not so much elsewhere, and that anywhere there
> is a partition, there is the possibility of using wedges, it would
> seem that this is essential.

I would think it's not just CDs and hypervisor-provided virtual devices
that can have multiple partitions, use wedges, and yet be read-only.

Are not a wide variety of removable storage devices also capable of
being made "read-only" at the hardware level?

On Apr 4,  7:34, Michael van Elst wrote:
>
> I suggested to make it open read-only if it gets EROFS and to validate
> the open mode against what is possible in this state.

Given the layers of devices and code involved, perhaps it might be
possible to just honour the original mode requested by the code opening
the first partition to mount a filesystem, and then to upgrade the vnode
to write mode if/when that mount is upgraded to write mode or another rw
mount is attempted on another partition on the same device?

I realize there's nothing like VOP_REOPEN() to change the open mode
flags, but if I'm not mistaken that wouldn't be too difficult to
implement.

Anyway I did find this is where the actual EROFS is being returned, and
perhaps changing it to EACCES would be less confusing, or maybe not

--- sys/arch/xen/xen/xbd_xenbus.c.~1.129.~  2021-02-28 15:45:22.0 
-0800
+++ sys/arch/xen/xen/xbd_xenbus.c   2021-04-04 14:21:01.006355121 -0700
@@ -950,7 +950,7 @@
if (sc == NULL)
return (ENXIO);
if ((flags & FWRITE) && (sc->sc_info & VDISK_READONLY))
-   return EROFS;
+   return EACCES;

DPRINTF(("xbdopen(%" PRIx64 ", %d)\n", dev, flags));
return dk_open(&sc->sc_dksc, dev, flags, fmt, l);



--
Greg A. Woods 

Kelowna, BC +1 250 762-7675   RoboHack 
Planix, Inc.  Avoncote Farms 


pgpD2yAUtTyIh.pgp
Description: OpenPGP Digital Signature


Re: how do I mount a read-only filesystem from the "root device" prompt?

2021-04-04 Thread John Nemeth
On Apr 4,  7:34, Michael van Elst wrote:
} wo...@planix.ca ("Greg A. Woods") writes:
} 
} >So with Xen one can export a "disk" (disk, file, LVM partiion, etc.)
} >with "access=ro", and that is enforced.
} 
} >However if one tries to mount such a disk in a domU as root, it fails.
} 
} > root on dk1
} > vfs_mountroot: can't open root device, error = 30
} > cannot mount root, error = 30
} 
} 
} The wedge code always opens the parent device read-write as it is only
} opened once for all wedges.
} 
} I suggested to make it open read-only if it gets EROFS and to validate
} the open mode against what is possible in this state.

 Given that it is possible to have partitions on CDs, which is
common on Suns, but not so much elsewhere, and that anywhere there
is a partition, there is the possibility of using wedges, it would
seem that this is essential.

}-- End of excerpt from Michael van Elst


Re: how do I mount a read-only filesystem from the "root device" prompt?

2021-04-04 Thread Michael van Elst
wo...@planix.ca ("Greg A. Woods") writes:

>So with Xen one can export a "disk" (disk, file, LVM partiion, etc.)
>with "access=ro", and that is enforced.

>However if one tries to mount such a disk in a domU as root, it fails.

>   root on dk1
>   vfs_mountroot: can't open root device, error = 30
>   cannot mount root, error = 30


The wedge code always opens the parent device read-write as it is only
opened once for all wedges.

I suggested to make it open read-only if it gets EROFS and to validate
the open mode against what is possible in this state.



how do I mount a read-only filesystem from the "root device" prompt?

2021-04-03 Thread Greg A. Woods
So with Xen one can export a "disk" (disk, file, LVM partiion, etc.)
with "access=ro", and that is enforced.

However if one tries to mount such a disk in a domU as root, it fails.

When one first looks at the code which does the initial vfs_mountroot it
would appear to be correct -- i.e. it is trying to open the root
filesystem device for reading it uses VOP_OPEN() to open the root
device with FREAD (which I think means "only for reading"):

error = VOP_OPEN(rootvp, FREAD, FSCRED);
if (error) {
printf("vfs_mountroot: can't open root device, error = 
%d\n", error);
return (error);
}

However something assumes that if it is like a disk (i.e. but not a
CD-ROM/DVD) then it tries to open for write too as we get:

root on dk1
vfs_mountroot: can't open root device, error = 30
cannot mount root, error = 30

(errno #30 is of course EROFS)

I'm not even sure where this is happening.

vfs_rootmountalloc() does indeed set MNT_RDONLY, but this error is
happening before vfs_mountroot() calls ffs_mountroot (through the
vfs_mountroot pointer).

So I'm lost -- any hints?  Is it from bounds_check_with_label()?  How?

--
Greg A. Woods 

Kelowna, BC +1 250 762-7675   RoboHack 
Planix, Inc.  Avoncote Farms 


pgp1QhMimCiG1.pgp
Description: OpenPGP Digital Signature