Date: Mon, 7 Sep 2020 23:22:16 +0000 (UTC) From: Mark Johnston <markj@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r365436 - stable/12/sbin/ggate/ggated Message-ID: <202009072322.087NMGK9071255@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: markj Date: Mon Sep 7 23:22:16 2020 New Revision: 365436 URL: https://svnweb.freebsd.org/changeset/base/365436 Log: MFC r364995: ggated(8): Avoid doubly opening the requested disk device. PR: 132845 Modified: stable/12/sbin/ggate/ggated/ggated.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sbin/ggate/ggated/ggated.c ============================================================================== --- stable/12/sbin/ggate/ggated/ggated.c Mon Sep 7 23:21:53 2020 (r365435) +++ stable/12/sbin/ggate/ggated/ggated.c Mon Sep 7 23:22:16 2020 (r365436) @@ -349,6 +349,16 @@ exports_check(struct ggd_export *ex, struct g_gate_cin flags = O_WRONLY; else flags = O_RDWR; + if (conn->c_diskfd != -1) { + if (strcmp(conn->c_path, ex->e_path) != 0) { + g_gate_log(LOG_ERR, "old %s and new %s: " + "Path mismatch during handshakes.", + conn->c_path, ex->e_path); + return (EPERM); + } + return (0); + } + conn->c_diskfd = open(ex->e_path, flags); if (conn->c_diskfd == -1) { error = errno; @@ -455,7 +465,7 @@ connection_new(struct g_gate_cinit *cinit, struct sock conn->c_token = cinit->gc_token; ip = htonl(((struct sockaddr_in *)(void *)s)->sin_addr.s_addr); conn->c_srcip = ip; - conn->c_sendfd = conn->c_recvfd = -1; + conn->c_diskfd = conn->c_sendfd = conn->c_recvfd = -1; if ((cinit->gc_flags & GGATE_FLAG_SEND) != 0) conn->c_sendfd = sfd; else @@ -510,6 +520,8 @@ connection_remove(struct ggd_connection *conn) LIST_REMOVE(conn, c_next); g_gate_log(LOG_DEBUG, "Connection removed [%s %s].", ip2str(conn->c_srcip), conn->c_path); + if (conn->c_diskfd != -1) + close(conn->c_diskfd); if (conn->c_sendfd != -1) close(conn->c_sendfd); if (conn->c_recvfd != -1)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202009072322.087NMGK9071255>