Skip to contentSkip to conversation

fsck: Add support for "completion" scripts.

PATCH In review Frank Mayhar 2 participants 6 messages Feb 7, 2012 – Feb 9, 2012 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 4/4 fsck: Add support for "completion" scripts.

Add support for scripts that are run when each individual fsck completes. This allows certain general or file- or device-specific actions to be taken when each fsck finishes.

 fsck/fsck.8 |   60
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fsck/fsck.c |   62
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fsck/fsck.h |    4 ++-
 3 files changed, 125 insertions(+), 1 deletions(-)
fsck/fsck.8 +3 -0
index d56b0d7..7e5b55b 100644
@@ -413,6 +413,60 @@ and
 do not support the
 .B -y
 option as of this writing.
+.SH COMPLETION SCRIPTS
+.B fsck
+has a mechanism available by which to run a script when each check

completes.
+If when
+.B fsck
+starts the directory
+.IR /etc/fsck.d
+(or see FSCK_COMPLETION_PATH below) exists and is readable, +.B fsck
+will use it to find such scripts. Scripts there must be named one of +.IR /etc/fsck.d/device/name ", " /etc/fsck.d/fstype/name , +or
+.IR /etc/fsck.d/completion ,
+where
+.I name
+is either the last component of the device path (e.g.
+.IR /etc/fsck.d/device/hda1 )
+or a file system type (e.g.
+.IR /etc/fsck.d/fstype/ext4 ).
+.PP
+When a file system check completes,
+.B fsck
+looks for a script that corresponds to the device that was checked; if such
+a script is not found it looks for a script that corresponds to the +type of that file system. If neither of those is found it looks for a +script named
+.IR /etc/fsck.d/completion .
+When
+.B fsck
+finds such a script and if the script is executable (and the +.B \-N
+option was not specified), it runs the script via the
+.I system(3)
+function, passing the following set of parameters on the command line:
+.br
+\ device\ \-\ Device path of the device checked
+.br
+\ type\ \ \-\ File system type
+.br
+\ status\ \-\ Exit status
+.br
+\ elapsed\ \-\ Elapsed wall-clock time
+.br
+\ utime\ \-\ User CPU time
+.br
+\ stime\ \-\ System CPU time
+.br
+\ maxrss\ \-\ Maximum run-set-size
+.br
+\ logpath\ \-\ Path to logfile if the \-L option was specified
+.PP
+For example:
+.br
+ /etc/fsck.d/device/hdc1 /dev/hdc1 ext4 0 1.60470 0.41193 0.76588 9828 .SH AUTHOR
.UR tytso\@mit.edu
Theodore Ts'o
@@ -429,6 +483,12 @@ The
.B fsck
program's behavior is affected by the following environment variables:
.TP
+.B FSCK_COMPLETION_PATH
+If this environment variable is set,
+.B fsck
+will look for completion scripts in the indicated directory rather than in
+.IR /etc/fsck.d .
+.TP
.B FSCK_FORCE_ALL_PARALLEL
If this environment variable is set,
.B fsck

fsck/fsck.c +62 -0

86 lines not on this page · raw message

fsck/fsck.h +3 -1
index 6e41f40..93356bc 100644
@@ -33,8 +33,10 @@
 #define EXIT_TIMEOUT     64
 #define EXIT_LIBRARY     128
 
+#define COMPLETION_PATH	"/etc/fsck.d/"
+
 /*
- * Internal structure for mount tabel entries.
+ * Internal structure for mount table entries.
  */
 
 struct fs_info {
Signature · 2 lines
Frank Mayhar
[email protected]
maintainer
#1 lore raw
Quoted 25 lines · Frank Mayhar

Add support for scripts that are run when each individual fsck completes. This allows certain general or file- or device-specific actions to be taken when each fsck finishes.

 fsck/fsck.8 |   60
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fsck/fsck.c |   62
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fsck/fsck.h |    4 ++-
 3 files changed, 125 insertions(+), 1 deletions(-)
fsck/fsck.8 +3 -0
index d56b0d7..7e5b55b 100644
@@ -413,6 +413,60 @@ and
 do not support the
 .B -y
 option as of this writing.
+.SH COMPLETION SCRIPTS
+.B fsck
+has a mechanism available by which to run a script when each check

completes.

fsck/fsck.8

Quoted 8 lines
fsck/fsck.8 +8 -0
+If when
+.B fsck
+starts the directory
+.IR /etc/fsck.d
+(or see FSCK_COMPLETION_PATH below) exists and is readable,
+.B fsck
+will use it to find such scripts.  Scripts there must be named one of
+.IR /etc/fsck.d/device/name ", " /etc/fsck.d/fstype/name ,

The problem is that "device name" is whatever from fsck command line or from first fstab column.

Unfortunately the current fsck code does not canonicalize the device name -- this is bug because in the function ignore() we stat() the device... I'll fix this problem ASAP.

Maybe it would be better to somehow standardize the names used for fsck-log and the completion scripts.

What about to use

    /etc/fsck.d/uuid/<uuid>
    /var/log/fsck/fsck-<uuid>

rather than devname? I guess that all usable filesystems provides UUIDs now and fsck is already linked with libblkid.

If you agree than ignore this problem for now, I'll implement it.

Quoted 1 line

+.I system(3)

Why we need to execute the scripts by system(3)? Why not classic execv?

Quoted 11 lines
fsck/fsck.8 +11 -0
+function, passing the following set of parameters on the command line:
+.br
+\	device\	\-\ Device path of the device checked
+.br
+\	type\	\	\-\ File system type
+.br
+\	status\	\-\ Exit status
+.br
+\	elapsed\	\-\ Elapsed wall-clock time
+.br
+\	utime\	\-\ User CPU time

fsck/fsck.8

Quoted 10 lines
fsck/fsck.8 +10 -0
+.br
+\	stime\	\-\ System CPU time
+.br
+\	maxrss\	\-\ Maximum run-set-size
+.br
+\	logpath\	\-\ Path to logfile if the \-L option was specified
+.PP
+For example:
+.br
+  /etc/fsck.d/device/hdc1 /dev/hdc1 ext4 0 1.60470 0.41193 0.76588 9828

I don't like the fixed set of parameters, it will be difficult to extend such solution in the future.

What about to set environment variables FSCK_{DEVICE,FSTYPE,UTIME,...} for the script or use regular command line options, so:

    /etc/fsck.d/completion --device=/dev/hda1 --fstype=ext4 ...


    Karel
Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#2 lore raw
Quoted 38 lines · Karel Zak
Quoted 25 lines · Frank Mayhar

Add support for scripts that are run when each individual fsck completes. This allows certain general or file- or device-specific actions to be taken when each fsck finishes.

 fsck/fsck.8 |   60
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fsck/fsck.c |   62
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fsck/fsck.h |    4 ++-
 3 files changed, 125 insertions(+), 1 deletions(-)
fsck/fsck.8 +3 -0
index d56b0d7..7e5b55b 100644
@@ -413,6 +413,60 @@ and
 do not support the
 .B -y
 option as of this writing.
+.SH COMPLETION SCRIPTS
+.B fsck
+has a mechanism available by which to run a script when each check

completes.

fsck/fsck.8

Quoted 8 lines
fsck/fsck.8 +8 -0
+If when
+.B fsck
+starts the directory
+.IR /etc/fsck.d
+(or see FSCK_COMPLETION_PATH below) exists and is readable,
+.B fsck
+will use it to find such scripts.  Scripts there must be named one of
+.IR /etc/fsck.d/device/name ", " /etc/fsck.d/fstype/name ,

The problem is that "device name" is whatever from fsck command line or from first fstab column.

Quoted 3 lines

Unfortunately the current fsck code does not canonicalize the device name -- this is bug because in the function ignore() we stat() the device... I'll fix this problem ASAP.

If the device name is canonicalized, I think the problem generally goes away.

Quoted 7 lines

Maybe it would be better to somehow standardize the names used for fsck-log and the completion scripts.

What about to use

    /etc/fsck.d/uuid/<uuid>
    /var/log/fsck/fsck-<uuid>

Adding the uuid as a potential completion script makes a lot of sense; I'm a little hesitant about using the uuid in the logfile name, since it's typically pretty long and could easily make the filename unwieldy. That's part of what the completion script is for, too: To potentially canonicalize the logfile name into whatever form makes sense locally.

I would want to keep the devname, fstype and generic completion scripts the same, though. Just add the uuid one as you indicate.

Quoted 8 lines

rather than devname? I guess that all usable filesystems provides UUIDs now and fsck is already linked with libblkid.

If you agree than ignore this problem for now, I'll implement it.

Quoted 1 line

+.I system(3)

Why we need to execute the scripts by system(3)? Why not classic execv?

The completion script could as easily be an executable binary; I just figured I would let system() take care of it for me. If you have a strong objection, I could change it but at the moment I see no strong reason to worry about it.

Quoted 4 lines
Quoted 1 line

+ /etc/fsck.d/device/hdc1 /dev/hdc1 ext4 0 1.60470 0.41193 0.76588 9828

I don't like the fixed set of parameters, it will be difficult to extend such solution in the future.

Mostly I wanted something that would be trivial to parse. I thought about regular command line options but that makes the completion script a lot bigger (all the option-parsing code) and my goal was to keep things as simple as possible. Setting environment variables might be sufficient, though.

One thing I remembered last night that I forgot to document is that the last parameter is optional and is the logfile name (including path) if the -L option was given. I'll generate one more patch to fsck.8 (based on the current set of patches) to fix that, although if we go with environment variables then it's no longer a problem.

For my own purposes, I would really like to keep the invocation as-is and fall back to environment variables if there are no arguments on the command line. This would make my life a _lot_ easier.

Signature · 2 lines
Frank Mayhar
[email protected]
maintainer
#3 lore raw
Quoted 9 lines · Frank Mayhar
Quoted 6 lines

The problem is that "device name" is whatever from fsck command line or from first fstab column.

Unfortunately the current fsck code does not canonicalize the device name -- this is bug because in the function ignore() we stat() the device... I'll fix this problem ASAP.

If the device name is canonicalized, I think the problem generally goes away.

You miss the point. Yes, we can resolve the problem with UUID= or LABEL= in /etc/fstab, but the problem is that nothing guarantees that the canonical kernel device name (e.g. /dev/sda) will the same after reboot. This is reason why we use things like UUID= or /dev/disk/by-* for block devices.

Anyway, no problem to support /etc/fsck.d/<devname>/ but preferred and recommended will be definitely <uuid>.

Quoted 31 lines
Quoted 7 lines

Maybe it would be better to somehow standardize the names used for fsck-log and the completion scripts.

What about to use

    /etc/fsck.d/uuid/<uuid>
    /var/log/fsck/fsck-<uuid>

Adding the uuid as a potential completion script makes a lot of sense; I'm a little hesitant about using the uuid in the logfile name, since it's typically pretty long and could easily make the filename unwieldy. That's part of what the completion script is for, too: To potentially canonicalize the logfile name into whatever form makes sense locally.

I would want to keep the devname, fstype and generic completion scripts the same, though. Just add the uuid one as you indicate.

Quoted 8 lines

rather than devname? I guess that all usable filesystems provides UUIDs now and fsck is already linked with libblkid.

If you agree than ignore this problem for now, I'll implement it.

Quoted 1 line

+.I system(3)

Why we need to execute the scripts by system(3)? Why not classic execv?

The completion script could as easily be an executable binary; I just figured I would let system() take care of it for me. If you have a strong objection, I could change it but at the moment I see no strong reason to worry about it.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

+ /etc/fsck.d/device/hdc1 /dev/hdc1 ext4 0 1.60470 0.41193 0.76588 9828

I don't like the fixed set of parameters, it will be difficult to extend such solution in the future.

Mostly I wanted something that would be trivial to parse. I thought about regular command line options but that makes the completion script a lot bigger (all the option-parsing code)

Good point.

Quoted 10 lines

and my goal was to keep
things as simple as possible. Setting environment variables might be sufficient, though.

One thing I remembered last night that I forgot to document is that the last parameter is optional and is the logfile name (including path) if the -L option was given. I'll generate one more patch to fsck.8 (based on the current set of patches) to fix that, although if we go with environment variables then it's no longer a problem.

Quoted 3 lines

For my own purposes, I would really like to keep the invocation as-is and fall back to environment variables if there are no arguments on the command line. This would make my life a _lot_ easier.

I understand, but I'd like to have a solution which is usable for more people and easy to maintain for upstream :-) What about

/etc/fsck.d/completion <devname> <status>

and the rest of information by FSCK_* env.variables ? The env. variables should be pretty simple to use in the script.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#4 lore raw
Quoted 8 lines · Karel Zak
Quoted 7 lines · Frank Mayhar
Quoted 6 lines

The problem is that "device name" is whatever from fsck command line or from first fstab column.

Unfortunately the current fsck code does not canonicalize the device name -- this is bug because in the function ignore() we stat() the device... I'll fix this problem ASAP.

Quoted 8 lines
Quoted 2 lines

If the device name is canonicalized, I think the problem generally goes away.

You miss the point. Yes, we can resolve the problem with UUID= or LABEL= in /etc/fstab, but the problem is that nothing guarantees that the canonical kernel device name (e.g. /dev/sda) will the same after reboot. This is reason why we use things like UUID= or /dev/disk/by-* for block devices.

This is true in the general case but is more of an administrative issue (in my opinion) and depends heavily on the configuration (of both the machine and the distribution). (In my _particular_ case, it isn't true, in fact.) Regardless, however, the real reason I'm resistant to using the uuid for the logfile name is that it's just not very human-friendly. That may also be true for certain kinds of device names, but to me "fsck-d0c0t0s0" or "fsck-sda1" is much easier to deal with than "fsck-bfb8fb54-5b31-11df-98e8-00e081337e9a".

Quoted 2 lines

Anyway, no problem to support /etc/fsck.d/<devname>/ but preferred and recommended will be definitely <uuid>.

My inclination is to leave it up to the individual admin, but I have no strong feeling about it.

Quoted 14 lines
Quoted 10 lines

and my goal was to keep
things as simple as possible. Setting environment variables might be sufficient, though.

One thing I remembered last night that I forgot to document is that the last parameter is optional and is the logfile name (including path) if the -L option was given. I'll generate one more patch to fsck.8 (based on the current set of patches) to fix that, although if we go with environment variables then it's no longer a problem.

Quoted 3 lines

For my own purposes, I would really like to keep the invocation as-is and fall back to environment variables if there are no arguments on the command line. This would make my life a _lot_ easier.

Quoted 7 lines

I understand, but I'd like to have a solution which is usable for more people and easy to maintain for upstream :-) What about

/etc/fsck.d/completion <devname> <status>

and the rest of information by FSCK_* env.variables ? The env. variables should be pretty simple to use in the script.

Yeah, I could go with this. Do you want to code it up or shall I?

Signature · 2 lines
Frank Mayhar
[email protected]
maintainer
#5 lore raw
Quoted 1 line · Frank Mayhar

Yeah, I could go with this. Do you want to code it up or shall I?

No, I'll play with it later and it seems that we can cleanup more things in fsck (it's too late for v2.21 now).

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com