9front - general discussion about 9front
 help / color / mirror / Atom feed
* -d option for fshalt
@ 2020-06-02  4:37 Alex Musolino
  2020-06-02  4:58 ` [9front] " Alex Musolino
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Alex Musolino @ 2020-06-02  4:37 UTC (permalink / raw)
  To: 9front

Hi all,

I've added support for a -d option in fshalt(8) that triggers a dump
of the local filesystem before halting.  I've found it useful in my
current situation where my 9front machine spends most of its time
powered off.

Any objections to the following?

diff -r 8006152d13d2 rc/bin/fshalt
--- a/rc/bin/fshalt	Tue Apr 28 20:51:19 2020 -0700
+++ b/rc/bin/fshalt	Tue Jun 02 14:03:03 2020 +0930
@@ -1,16 +1,20 @@
 #!/bin/rc
-# fshalt [-r] - sync (flush) and, if possible, halt all file servers
-#	and optionally reboot
 rfork en
+dump=no
 reboot=no
 scram=no
-switch ($#*) {
-case 0
-case 1
-	reboot=yes
-case *
-	echo usage: $0 '[-r]' >[1=2]
-	exit usage
+
+while (~ $1 -*) {
+	switch ($1) {
+	case -d
+		dump=yes
+	case -r
+		reboot=yes
+	case *
+		echo usage: $0 '[-r]' >[1=2]
+		exit usage
+	}
+	shift
 }
 
 path=(/bin)
@@ -53,6 +57,13 @@
 # when it's no longer accessible
 fn x {
 	echo
+	echo -n dumping...
+	if (~ $dump yes) {
+		for (i in $c $h)
+			echo dump >>$i
+	}
+
+	echo
 	echo -n halting...
 	for (i in $c $h)
 		echo halt >>$i
diff -r 8006152d13d2 sys/man/8/fshalt
--- a/sys/man/8/fshalt	Tue Apr 28 20:51:19 2020 -0700
+++ b/sys/man/8/fshalt	Tue Jun 02 14:03:03 2020 +0930
@@ -4,6 +4,8 @@
 .SH SYNOPSIS
 .B fshalt
 [
+.B -d
+] [
 .B -r
 ]
 .br
@@ -20,13 +22,15 @@
 and
 .IR hjfs (4)
 servers.
-If given
-.BR -r ,
-.I fshalt
-will then reboot the machine.
-Else it will invoke
+The
+.BR -d
+option causes a dump command to be issued to the local filesystem
+before the sync and halt commands.  Once any filesystems have been
+halted,
 .I scram
-to shut down the machine.
+will be invoked to shut down the machine, unless the
+.BR -r
+option is specified, in which case the machine is instead rebooted.
 The halting and rebooting is done by copying all necessary
 commands into a
 .IR ramfs (4)


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

* Re: [9front] -d option for fshalt
  2020-06-02  4:37 -d option for fshalt Alex Musolino
@ 2020-06-02  4:58 ` Alex Musolino
  2020-06-02  6:54 ` Alex Musolino
  2020-06-02  6:59 ` rgl
  2 siblings, 0 replies; 8+ messages in thread
From: Alex Musolino @ 2020-06-02  4:58 UTC (permalink / raw)
  To: 9front

> +before the sync and halt commands.  Once any filesystems have been

Reviewing my own patch: there is no "sync" command so this
should just be "before the halt command".


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

* Re: [9front] -d option for fshalt
  2020-06-02  4:37 -d option for fshalt Alex Musolino
  2020-06-02  4:58 ` [9front] " Alex Musolino
@ 2020-06-02  6:54 ` Alex Musolino
  2020-06-02  6:59 ` rgl
  2 siblings, 0 replies; 8+ messages in thread
From: Alex Musolino @ 2020-06-02  6:54 UTC (permalink / raw)
  To: 9front

> +	echo -n dumping...
> +	if (~ $dump yes) {

Ugh, and the "dumping..." diagnostic should only be displayed
if we are, in fact, taking a dump.


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

* Re: [9front] -d option for fshalt
  2020-06-02  4:37 -d option for fshalt Alex Musolino
  2020-06-02  4:58 ` [9front] " Alex Musolino
  2020-06-02  6:54 ` Alex Musolino
@ 2020-06-02  6:59 ` rgl
  2020-06-04  6:57   ` Alex Musolino
  2 siblings, 1 reply; 8+ messages in thread
From: rgl @ 2020-06-02  6:59 UTC (permalink / raw)
  To: 9front

-		echo usage: $0 '[-r]' >[1=2]
+		echo usage: $0 '[-rd]' >[1=2]



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

* Re: [9front] -d option for fshalt
  2020-06-02  6:59 ` rgl
@ 2020-06-04  6:57   ` Alex Musolino
  2020-06-04 12:27     ` kvik
  0 siblings, 1 reply; 8+ messages in thread
From: Alex Musolino @ 2020-06-04  6:57 UTC (permalink / raw)
  To: 9front

> -		echo usage: $0 '[-r]' >[1=2]
> +		echo usage: $0 '[-rd]' >[1=2]

Good catch.  I opted for '[-d] [-r]' to match what I have in
the man page.  The were separated in the first place so as not
to provide a misleading example; Fshalt will *not* parse the
individual flags out of a single '-rd' argument.

Updated patch follows.

diff -r ff6b294d07a9 rc/bin/fshalt
--- a/rc/bin/fshalt	Mon Jun 01 00:07:01 2020 +0200
+++ b/rc/bin/fshalt	Thu Jun 04 16:22:02 2020 +0930
@@ -1,16 +1,20 @@
 #!/bin/rc
-# fshalt [-r] - sync (flush) and, if possible, halt all file servers
-#	and optionally reboot
 rfork en
+dump=no
 reboot=no
 scram=no
-switch ($#*) {
-case 0
-case 1
-	reboot=yes
-case *
-	echo usage: $0 '[-r]' >[1=2]
-	exit usage
+
+while (~ $1 -*) {
+	switch ($1) {
+	case -d
+		dump=yes
+	case -r
+		reboot=yes
+	case *
+		echo usage: $0 '[-d] [-r]' >[1=2]
+		exit usage
+	}
+	shift
 }
 
 path=(/bin)
@@ -52,6 +56,13 @@
 # put this in a shell function so this rc script doesn't get read
 # when it's no longer accessible
 fn x {
+	if (~ $dump yes) {
+		echo
+		echo -n dumping...
+		for (i in $c $h)
+			echo dump >>$i
+	}
+
 	echo
 	echo -n halting...
 	for (i in $c $h)
diff -r ff6b294d07a9 sys/man/8/fshalt
--- a/sys/man/8/fshalt	Mon Jun 01 00:07:01 2020 +0200
+++ b/sys/man/8/fshalt	Thu Jun 04 16:22:02 2020 +0930
@@ -4,6 +4,8 @@
 .SH SYNOPSIS
 .B fshalt
 [
+.B -d
+] [
 .B -r
 ]
 .br
@@ -20,13 +22,15 @@
 and
 .IR hjfs (4)
 servers.
-If given
-.BR -r ,
-.I fshalt
-will then reboot the machine.
-Else it will invoke
+The
+.BR -d
+option causes a dump command to be issued to the local filesystem
+before the sync and halt commands.  Once any filesystems have been
+halted,
 .I scram
-to shut down the machine.
+will be invoked to shut down the machine, unless the
+.BR -r
+option is specified, in which case the machine is instead rebooted.
 The halting and rebooting is done by copying all necessary
 commands into a
 .IR ramfs (4)


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

* Re: [9front] -d option for fshalt
  2020-06-04  6:57   ` Alex Musolino
@ 2020-06-04 12:27     ` kvik
  2020-06-04 13:57       ` Alex Musolino
  0 siblings, 1 reply; 8+ messages in thread
From: kvik @ 2020-06-04 12:27 UTC (permalink / raw)
  To: 9front

Seems like a reasonably useful option to have, though I'm inclined to
suggest a standalone dump [fscons ...] utility as an alternative that
one might conveniently use on its own, or combined with a halt:

	dump && fshalt

> Updated patch follows.

While I'd suggest perusing the new and improved getflags(8) to parse
the arguments the patch looks mostly good to me.

Replace the -* while loop with:

	flagfmt = 'd:dump, r:reboot'
	eval `''{aux/getflags $*} || exec aux/usage

And change "yes / no" to "1 / 0" where appropriate.


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

* Re: [9front] -d option for fshalt
  2020-06-04 12:27     ` kvik
@ 2020-06-04 13:57       ` Alex Musolino
  2020-06-04 15:50         ` kvik
  0 siblings, 1 reply; 8+ messages in thread
From: Alex Musolino @ 2020-06-04 13:57 UTC (permalink / raw)
  To: 9front

> Seems like a reasonably useful option to have, though I'm inclined to
> suggest a standalone dump [fscons ...] utility as an alternative that
> one might conveniently use on its own, or combined with a halt:
> 
> 	dump && fshalt

Yeah, that's fair comment.  Something like this:

#!/bin/rc
rfork E
if(~ $#* 0){
	c=`{ls /srv/cwfs*cmd >[2]/dev/null}
	h=`{ls /srv/hjfs*cmd >[2]/dev/null}
}
for (i in $* $c $h)
	echo dump >>$i

Perhaps we call it fsdump to go with fshalt?

> While I'd suggest perusing the new and improved getflags(8) to parse
> the arguments the patch looks mostly good to me.
> 
> Replace the -* while loop with:
> 
> 	flagfmt = 'd:dump, r:reboot'
> 	eval `''{aux/getflags $*} || exec aux/usage
> 
> And change "yes / no" to "1 / 0" where appropriate.

I did think about this but figured I'd do it separately (if at all) in
the interest of keeping the patch small and focused.  Anyway, might
be moot now.


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

* Re: [9front] -d option for fshalt
  2020-06-04 13:57       ` Alex Musolino
@ 2020-06-04 15:50         ` kvik
  0 siblings, 0 replies; 8+ messages in thread
From: kvik @ 2020-06-04 15:50 UTC (permalink / raw)
  To: 9front

fsdump sounds good.


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

end of thread, other threads:[~2020-06-04 15:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02  4:37 -d option for fshalt Alex Musolino
2020-06-02  4:58 ` [9front] " Alex Musolino
2020-06-02  6:54 ` Alex Musolino
2020-06-02  6:59 ` rgl
2020-06-04  6:57   ` Alex Musolino
2020-06-04 12:27     ` kvik
2020-06-04 13:57       ` Alex Musolino
2020-06-04 15:50         ` kvik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).