From owner-svn-src-all@freebsd.org Tue Mar 22 22:41:08 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D542AADA5AF; Tue, 22 Mar 2016 22:41:08 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AFACDE2E; Tue, 22 Mar 2016 22:41:08 +0000 (UTC) (envelope-from bdrewery@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u2MMf7e8090073; Tue, 22 Mar 2016 22:41:07 GMT (envelope-from bdrewery@FreeBSD.org) Received: (from bdrewery@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u2MMf7ub090070; Tue, 22 Mar 2016 22:41:07 GMT (envelope-from bdrewery@FreeBSD.org) Message-Id: <201603222241.u2MMf7ub090070@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bdrewery set sender to bdrewery@FreeBSD.org using -f From: Bryan Drewery Date: Tue, 22 Mar 2016 22:41:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r297201 - in head: share/man/man4 sys/dev/filemon X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Mar 2016 22:41:08 -0000 Author: bdrewery Date: Tue Mar 22 22:41:07 2016 New Revision: 297201 URL: https://svnweb.freebsd.org/changeset/base/297201 Log: Return any log write failure encountered when closing the filemon fd. Discussed with: sjg, markj Reviewed by: sjg MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Modified: head/share/man/man4/filemon.4 head/sys/dev/filemon/filemon.c head/sys/dev/filemon/filemon_wrapper.c Modified: head/share/man/man4/filemon.4 ============================================================================== --- head/share/man/man4/filemon.4 Tue Mar 22 22:41:03 2016 (r297200) +++ head/share/man/man4/filemon.4 Tue Mar 22 22:41:07 2016 (r297201) @@ -161,6 +161,12 @@ No process having the specified process The process ID specified is already being traced and was not the current process. .El +.Pp +The +.Fn close +system call on the filemon file descriptor may fail with the errors from +.Xr write 2 +if any error is encountered while writing the log. .Sh FILES .Bl -tag -width ".Pa /dev/filemon" .It Pa /dev/filemon Modified: head/sys/dev/filemon/filemon.c ============================================================================== --- head/sys/dev/filemon/filemon.c Tue Mar 22 22:41:03 2016 (r297200) +++ head/sys/dev/filemon/filemon.c Tue Mar 22 22:41:07 2016 (r297201) @@ -92,6 +92,7 @@ struct filemon { char fname1[MAXPATHLEN]; /* Temporary filename buffer. */ char fname2[MAXPATHLEN]; /* Temporary filename buffer. */ char msgbufr[1024]; /* Output message buffer. */ + int error; /* Log write error, returned on close(2). */ u_int refcnt; /* Pointer reference count. */ u_int proccnt; /* Process count. */ }; @@ -277,7 +278,10 @@ filemon_close_log(struct filemon *filemo return; } -/* The devfs file is being closed. Untrace all processes. */ +/* + * The devfs file is being closed. Untrace all processes. It is possible + * filemon_close/close(2) was not called. + */ static void filemon_dtr(void *data) { @@ -422,12 +426,28 @@ filemon_open(struct cdev *dev, int oflag return (error); } +/* Called on close of last devfs file handle, before filemon_dtr(). */ static int filemon_close(struct cdev *dev __unused, int flag __unused, int fmt __unused, struct thread *td __unused) { + struct filemon *filemon; + int error; - return (0); + if ((error = devfs_get_cdevpriv((void **) &filemon)) != 0) + return (error); + + sx_xlock(&filemon->lock); + filemon_close_log(filemon); + error = filemon->error; + sx_xunlock(&filemon->lock); + /* + * Processes are still being traced but won't log anything + * now. After this call returns filemon_dtr() is called which + * will detach processes. + */ + + return (error); } static void Modified: head/sys/dev/filemon/filemon_wrapper.c ============================================================================== --- head/sys/dev/filemon/filemon_wrapper.c Tue Mar 22 22:41:03 2016 (r297200) +++ head/sys/dev/filemon/filemon_wrapper.c Tue Mar 22 22:41:07 2016 (r297201) @@ -46,6 +46,7 @@ filemon_output(struct filemon *filemon, { struct uio auio; struct iovec aiov; + int error; if (filemon->fp == NULL) return; @@ -63,7 +64,9 @@ filemon_output(struct filemon *filemon, if (filemon->fp->f_type == DTYPE_VNODE) bwillwrite(); - fo_write(filemon->fp, &auio, curthread->td_ucred, 0, curthread); + error = fo_write(filemon->fp, &auio, curthread->td_ucred, 0, curthread); + if (error != 0) + filemon->error = error; } static int