Util-Linux Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 3/3] fstrim -a/-A: Skip read-only volumes
@ 2019-06-10 19:59 Stanislav Brabec
  2019-06-11  8:15 ` Karel Zak
  0 siblings, 1 reply; 3+ messages in thread
From: Stanislav Brabec @ 2019-06-10 19:59 UTC (permalink / raw)
  To: util-linux

Calling TRIM on some read-only volumes can fail with:
fstrim: /win: FITRIM ioctl failed: Bad file descriptor

Skipping all read-only mounts seems to be safe and logical strategy.

Fixes opensuse#1106214.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
---
 sys-utils/fstrim.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/sys-utils/fstrim.c b/sys-utils/fstrim.c
index 0491e2b54..e0e9e57a9 100644
--- a/sys-utils/fstrim.c
+++ b/sys-utils/fstrim.c
@@ -328,6 +328,14 @@ static int fstrim_all(struct fstrim_control *ctl)
 		if (rc)
 			continue;	/* overlaying mount */
 
+		/* FSTRIM on read-only filesystem can fail, and it can fail */
+		if (access(path, W_OK) != 0) {
+			if (errno == EROFS)
+				continue;
+			if (errno == EACCES)
+				continue;
+		}
+
 		if (!has_discard(src, &wholedisk))
 			continue;
 		cnt++;
-- 
2.21.0

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                         e-mail: sbrabec@suse.com
Køi¾íkova 148/34 (Corso IIa)                    tel: +420 284 084 060
186 00 Praha 8-Karlín                          fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 3/3] fstrim -a/-A: Skip read-only volumes
  2019-06-10 19:59 [PATCH 3/3] fstrim -a/-A: Skip read-only volumes Stanislav Brabec
@ 2019-06-11  8:15 ` Karel Zak
  2019-06-11 13:23   ` Stanislav Brabec
  0 siblings, 1 reply; 3+ messages in thread
From: Karel Zak @ 2019-06-11  8:15 UTC (permalink / raw)
  To: Stanislav Brabec; +Cc: util-linux

On Mon, Jun 10, 2019 at 09:59:45PM +0200, Stanislav Brabec wrote:
> Calling TRIM on some read-only volumes can fail with:
> fstrim: /win: FITRIM ioctl failed: Bad file descriptor

Did you try it with the current version from git? ... because we
interpret EBADF as "the discard operation is not supported" warning
rather than an error.

> Skipping all read-only mounts seems to be safe and logical strategy.
> 
> Fixes opensuse#1106214.
> 
> Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
> ---
>  sys-utils/fstrim.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/sys-utils/fstrim.c b/sys-utils/fstrim.c
> index 0491e2b54..e0e9e57a9 100644
> --- a/sys-utils/fstrim.c
> +++ b/sys-utils/fstrim.c
> @@ -328,6 +328,14 @@ static int fstrim_all(struct fstrim_control *ctl)
>  		if (rc)
>  			continue;	/* overlaying mount */
>  
> +		/* FSTRIM on read-only filesystem can fail, and it can fail */
> +		if (access(path, W_OK) != 0) {
> +			if (errno == EROFS)
> +				continue;
> +			if (errno == EACCES)
> +				continue;
> +		}
> +

Anyway, for fstrim_all() it's probably good idea to call access().

    Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 3/3] fstrim -a/-A: Skip read-only volumes
  2019-06-11  8:15 ` Karel Zak
@ 2019-06-11 13:23   ` Stanislav Brabec
  0 siblings, 0 replies; 3+ messages in thread
From: Stanislav Brabec @ 2019-06-11 13:23 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

Dne 11. 06. 19 v 10:15 Karel Zak napsal(a):
> On Mon, Jun 10, 2019 at 09:59:45PM +0200, Stanislav Brabec wrote:
>> Calling TRIM on some read-only volumes can fail with:
>> fstrim: /win: FITRIM ioctl failed: Bad file descriptor
> Did you try it with the current version from git? ... because we
> interpret EBADF as "the discard operation is not supported" warning
> rather than an error.

No. The bug was reported by one of users on a read-only /windows, and I
was not able to reproduce it. The patch was done as my best guess.

https://bugzilla.opensuse.org/show_bug.cgi?id=1106214

Reported for openSUSE Leap 15.0, i. e. util-linux-2.31.1.

I tried the same, but I found a possible bug in the ntfs:

mount -r /dev/nvme0n1p3 /windows
fuse: mount failed: Device or resource busy


-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                         e-mail: sbrabec@suse.com
Køi¾íkova 148/34 (Corso IIa)                    tel: +420 284 084 060
186 00 Praha 8-Karlín                          fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-10 19:59 [PATCH 3/3] fstrim -a/-A: Skip read-only volumes Stanislav Brabec
2019-06-11  8:15 ` Karel Zak
2019-06-11 13:23   ` Stanislav Brabec

Util-Linux Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/util-linux/0 util-linux/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 util-linux util-linux/ https://lore.kernel.org/util-linux \
		util-linux@vger.kernel.org util-linux@archiver.kernel.org
	public-inbox-index util-linux


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.util-linux


AGPL code for this site: git clone https://public-inbox.org/ public-inbox