From e3cd5a405a2780aaf16addf8405ec72f3b87c5b0 Mon Sep 17 00:00:00 2001 From: wblock Date: Thu, 9 Apr 2015 03:30:05 +0000 Subject: [PATCH 1/5] MFC 280988: Add articles, avoid use of "you", simplify a few sentences. --- ggatec/ggatec.8 | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/ggatec/ggatec.8 b/ggatec/ggatec.8 index 09f0444..12a1c53 100644 --- a/ggatec/ggatec.8 +++ b/ggatec/ggatec.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 26, 2004 +.Dd April 2, 2015 .Dt GGATEC 8 .Os .Sh NAME @@ -67,29 +67,29 @@ .Sh DESCRIPTION The .Nm -utility is a network client for GEOM Gate class. -It is responsible for creation of +utility is a network client for the GEOM Gate class. +It is responsible for the creation of .Nm ggate -devices and forwarding I/O requests between +devices and forwarding I/O requests between the .Nm geom_gate.ko -kernel module and +kernel module and the .Xr ggated 8 network daemon. Available commands: .Bl -tag -width ".Cm destroy" .It Cm create -Connect to given +Connect to a .Xr ggated 8 -daemon and create a +daemon on the specified host and create a .Nm ggate -provider related to the given remote file or device. +provider for the specified remote file or device. .It Cm rescue -If +Create a new connection after the .Nm -process died/has been killed, you can save situation with this -command, which creates new connection to the +process has died or been killed. +The new connection to the .Xr ggated 8 -daemon and will handle pending and future requests. +daemon handles pending and future requests. .It Cm destroy Destroy the given .Nm ggate @@ -139,12 +139,11 @@ provider. If not specified, it is taken from device, or set to 512 bytes for files. .It Fl t Ar timeout Number of seconds to wait before an I/O request will be canceled. -0 means no timeout. -Default is 0. +Default is 0, which means no timeout. .It Fl u Ar unit Unit number to use. .It Fl v -Do not fork, run in foreground and print debug informations on standard +Do not fork, run in foreground and print debug information on standard output. .It Ar host Remote host to connect to. @@ -159,7 +158,7 @@ should be called with the .Fl v option. .Sh EXAMPLES -Make use of CD-ROM device from remote host. +Use a CD-ROM device on a remote host. .Bd -literal -offset indent server# cat /etc/gg.exports client RO /dev/acd0 From 18d2e6bc238b48ef1757875f54149cfe8dcf6e11 Mon Sep 17 00:00:00 2001 From: jgh Date: Wed, 22 Apr 2015 18:54:51 +0000 Subject: [PATCH 2/5] MFC: r281324 - ggatel.8 currently doesn't mention the 'rescue' command and documents a non-existing 'attach' command instead. - while here address a spelling error Approved by: wblock (mentor) Differential Revision: https://reviews.freebsd.org/D2346 --- ggatel/ggatel.8 | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/ggatel/ggatel.8 b/ggatel/ggatel.8 index 236e550..6bfcedf 100644 --- a/ggatel/ggatel.8 +++ b/ggatel/ggatel.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 2, 2011 +.Dd April 9, 2015 .Dt GGATEL 8 .Os .Sh NAME @@ -40,12 +40,6 @@ .Op Fl u Ar unit .Ar path .Nm -.Cm attach -.Op Fl v -.Op Fl o Cm ro | wo | rw -.Fl u Ar unit -.Ar path -.Nm .Cm destroy .Op Fl f .Fl u Ar unit @@ -53,6 +47,12 @@ .Cm list .Op Fl v .Op Fl u Ar unit +.Nm +.Cm rescue +.Op Fl v +.Op Fl o Cm ro | wo | rw +.Fl u Ar unit +.Ar path .Sh DESCRIPTION The .Nm @@ -70,10 +70,6 @@ Available commands: Create a .Nm ggate provider related to the given regular file or device. -.It Cm attach -Attach a worker process to an existing -.Nm ggate -provider. .It Cm destroy Destroy the given .Nm ggate @@ -82,6 +78,12 @@ provider. List .Nm ggate providers. +.It Cm rescue +Take over a previously created provider and handle pending and future +requests. This is useful if the initial +.Nm +process died. To prevent data loss, the given path must lead to the +regular file or device that was used to create the provider. .El .Pp Available options: @@ -111,7 +113,7 @@ Default is 30. .It Fl u Ar unit Unit number to use. .It Fl v -Do not fork, run in foreground and print debug informations on standard +Do not fork, run in foreground and print debug information on standard output. .It Ar path Path to a regular file or device. From ab106a29771f223260ee49192fbf8fbc33178586 Mon Sep 17 00:00:00 2001 From: brueffer Date: Tue, 21 Jul 2015 14:25:21 +0000 Subject: [PATCH 3/5] MFC: r285531 Unbreak ggatec and ggatel on i386 after r238119, which added two more 'struct g_gate_ctl_create' fields. While the behaviour was technically undefined on other architectures as well, on the reporter's amd64 systems the uninitialized bytes the kernel cares about were always zero so everything worked as expected. PR: 197309, 199559 Submitted by: ota@j.email.ne.jp, Fabian Keil Reviewed by: pjd Approved by: re (gjb) --- ggatec/ggatec.c | 1 + ggatel/ggatel.c | 1 + 2 files changed, 2 insertions(+) diff --git a/ggatec/ggatec.c b/ggatec/ggatec.c index 6f9263c..ea4f701 100644 --- a/ggatec/ggatec.c +++ b/ggatec/ggatec.c @@ -447,6 +447,7 @@ g_gatec_create(void) /* * Ok, got both sockets, time to create provider. */ + memset(&ggioc, 0, sizeof(ggioc)); ggioc.gctl_version = G_GATE_VERSION; ggioc.gctl_mediasize = mediasize; ggioc.gctl_sectorsize = sectorsize; diff --git a/ggatel/ggatel.c b/ggatel/ggatel.c index abfe7c1..0b89df0 100644 --- a/ggatel/ggatel.c +++ b/ggatel/ggatel.c @@ -173,6 +173,7 @@ g_gatel_create(void) fd = open(path, g_gate_openflags(flags) | O_DIRECT | O_FSYNC); if (fd == -1) err(EXIT_FAILURE, "Cannot open %s", path); + memset(&ggioc, 0, sizeof(ggioc)); ggioc.gctl_version = G_GATE_VERSION; ggioc.gctl_unit = unit; ggioc.gctl_mediasize = g_gate_mediasize(fd); From 68e6f4213cc0e375ff9451e8c0670926b07f922e Mon Sep 17 00:00:00 2001 From: brueffer Date: Tue, 21 Jul 2015 14:27:36 +0000 Subject: [PATCH 4/5] MFC: r285529 If ggated's exports_find() fails, the connection is removed before (trying to) report the problem to the client. sendfail() is called with an already closed socket and thus it fails to inform the client about the problem. Fix this by calling sendfail() before connection_remove(). PR: 195944 Submitted by: Fabian Keil Reviewed by: pjd Approved by: re (gjb) --- ggated/ggated.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ggated/ggated.c b/ggated/ggated.c index 01aa00a..a340f01 100644 --- a/ggated/ggated.c +++ b/ggated/ggated.c @@ -906,8 +906,8 @@ handshake(struct sockaddr *from, int sfd) ex = exports_find(from, &cinit, conn); if (ex == NULL) { - connection_remove(conn); sendfail(sfd, errno, NULL); + connection_remove(conn); return (0); } if (conn->c_mediasize == 0) { From 1d384fcc69a6040ab637b9807734d24b51b2befc Mon Sep 17 00:00:00 2001 From: ngie Date: Sun, 13 Mar 2016 23:32:59 +0000 Subject: [PATCH 5/5] MFC r294973: Add pidfile support to ggated(8) The tests will manipulate the system daemon today, which can cause undesired service interruption when the tests are run. This change allows the geom_gate tests to be run with an arbitrary ggated(8) daemon / geom_gate(4) device pairing. Other changes: - Sort #includes - Use a more common idiom for parsing options with getopt(3) --- ggated/Makefile | 4 ++-- ggated/ggated.8 | 14 +++++++++++- ggated/ggated.c | 61 ++++++++++++++++++++++++++++++------------------- 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/ggated/Makefile b/ggated/Makefile index 4e7708e..d8cd8fd 100644 --- a/ggated/Makefile +++ b/ggated/Makefile @@ -6,8 +6,8 @@ PROG= ggated MAN= ggated.8 SRCS= ggated.c ggate.c -DPADD= ${LIBPTHREAD} -LDADD= -lpthread +DPADD= ${LIBPTHREAD} ${LIBUTIL} +LDADD= -lpthread -lutil CFLAGS+= -I${.CURDIR}/../shared diff --git a/ggated/ggated.8 b/ggated/ggated.8 index 3024a04..04b0513 100644 --- a/ggated/ggated.8 +++ b/ggated/ggated.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 29, 2004 +.Dd January 27, 2016 .Dt GGATED 8 .Os .Sh NAME @@ -37,6 +37,7 @@ .Op Fl v .Op Fl a Ar address .Op Fl p Ar port +.Op Fl F Ar pidfile .Op Fl R Ar rcvbuf .Op Fl S Ar sndbuf .Op Ar "exports file" @@ -67,6 +68,10 @@ Port on which .Nm listens for connection. Default is 3080. +.It Fl F Ar pidfile +PID file that +.Nm +uses. .It Fl R Ar rcvbuf Size of receive buffer to use. Default is 131072 (128kB). @@ -86,6 +91,13 @@ The format of an exports file is as follows: 1.2.3.0/24 RW /tmp/test.img hostname WO /tmp/image .Ed +.Sh FILES +.Bl -tag -width ".Pa /var/run/ggated.pid" -compact +.It Pa /var/run/ggated.pid +The default location of the +.Nm +PID file. +.El .Sh EXIT STATUS Exit status is 0 on success, or 1 if the command fails. To get details about the failure, diff --git a/ggated/ggated.c b/ggated/ggated.c index a340f01..e234cb5 100644 --- a/ggated/ggated.c +++ b/ggated/ggated.c @@ -26,32 +26,34 @@ * $FreeBSD$ */ -#include -#include -#include -#include -#include -#include #include -#include +#include +#include #include -#include #include +#include +#include #include #include -#include -#include +#include #include #include -#include -#include #include #include #include -#include +#include #include -#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include #include "ggate.h" @@ -110,8 +112,8 @@ static void usage(void) { - fprintf(stderr, "usage: %s [-nv] [-a address] [-p port] [-R rcvbuf] " - "[-S sndbuf] [exports file]\n", getprogname()); + fprintf(stderr, "usage: %s [-nv] [-a address] [-F pidfile] [-p port] " + "[-R rcvbuf] [-S sndbuf] [exports file]\n", getprogname()); exit(EXIT_FAILURE); } @@ -946,20 +948,18 @@ huphandler(int sig __unused) int main(int argc, char *argv[]) { + const char *ggated_pidfile = _PATH_VARRUN "/ggated.pid"; + struct pidfh *pfh; struct sockaddr_in serv; struct sockaddr from; socklen_t fromlen; - int sfd, tmpsfd; + pid_t otherpid; + int ch, sfd, tmpsfd; unsigned port; bindaddr = htonl(INADDR_ANY); port = G_GATE_PORT; - for (;;) { - int ch; - - ch = getopt(argc, argv, "a:hnp:R:S:v"); - if (ch == -1) - break; + while ((ch = getopt(argc, argv, "a:hnp:F:R:S:v")) != -1) { switch (ch) { case 'a': bindaddr = g_gate_str2ip(optarg); @@ -968,6 +968,9 @@ main(int argc, char *argv[]) "Invalid IP/host name to bind to."); } break; + case 'F': + ggated_pidfile = optarg; + break; case 'n': nagle = 0; break; @@ -1004,12 +1007,23 @@ main(int argc, char *argv[]) exports_file = argv[0]; exports_get(); + pfh = pidfile_open(ggated_pidfile, 0600, &otherpid); + if (pfh == NULL) { + if (errno == EEXIST) { + errx(EXIT_FAILURE, "Daemon already running, pid: %jd.", + (intmax_t)otherpid); + } + err(EXIT_FAILURE, "Cannot open/create pidfile"); + } + if (!g_gate_verbose) { /* Run in daemon mode. */ if (daemon(0, 0) == -1) g_gate_xlog("Cannot daemonize: %s", strerror(errno)); } + pidfile_write(pfh); + signal(SIGCHLD, SIG_IGN); sfd = socket(AF_INET, SOCK_STREAM, 0); @@ -1046,5 +1060,6 @@ main(int argc, char *argv[]) close(tmpsfd); } close(sfd); + pidfile_remove(pfh); exit(EXIT_SUCCESS); }