From owner-svn-src-head@freebsd.org Thu Feb 25 19:58:25 2016 Return-Path: Delivered-To: svn-src-head@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 11D3DAB44A9; Thu, 25 Feb 2016 19:58:25 +0000 (UTC) (envelope-from markj@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 E0B2F1CF; Thu, 25 Feb 2016 19:58:24 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u1PJwNgP064141; Thu, 25 Feb 2016 19:58:23 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u1PJwN8A064137; Thu, 25 Feb 2016 19:58:23 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201602251958.u1PJwN8A064137@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Thu, 25 Feb 2016 19:58:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r296060 - in head/sys: compat/freebsd32 kern sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Feb 2016 19:58:25 -0000 Author: markj Date: Thu Feb 25 19:58:23 2016 New Revision: 296060 URL: https://svnweb.freebsd.org/changeset/base/296060 Log: Improve error handling for posix_fallocate(2) and posix_fadvise(2). - Set td_errno so that ktrace and dtrace can obtain the syscall error number in the usual way. - Pass negative error numbers directly to the syscall layer, as they're not intended to be returned to userland. Reviewed by: kib Sponsored by: EMC / Isilon Storage Division Differential Revision: https://reviews.freebsd.org/D5425 Modified: head/sys/compat/freebsd32/freebsd32_misc.c head/sys/kern/sys_generic.c head/sys/kern/vfs_syscalls.c head/sys/sys/syscallsubr.h Modified: head/sys/compat/freebsd32/freebsd32_misc.c ============================================================================== --- head/sys/compat/freebsd32/freebsd32_misc.c Thu Feb 25 19:29:55 2016 (r296059) +++ head/sys/compat/freebsd32/freebsd32_misc.c Thu Feb 25 19:58:23 2016 (r296060) @@ -2965,21 +2965,22 @@ int freebsd32_posix_fallocate(struct thread *td, struct freebsd32_posix_fallocate_args *uap) { + int error; - td->td_retval[0] = kern_posix_fallocate(td, uap->fd, + error = kern_posix_fallocate(td, uap->fd, PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len)); - return (0); + return (kern_posix_error(td, error)); } int freebsd32_posix_fadvise(struct thread *td, struct freebsd32_posix_fadvise_args *uap) { + int error; - td->td_retval[0] = kern_posix_fadvise(td, uap->fd, - PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len), - uap->advice); - return (0); + error = kern_posix_fadvise(td, uap->fd, PAIR32TO64(off_t, uap->offset), + PAIR32TO64(off_t, uap->len), uap->advice); + return (kern_posix_error(td, error)); } int Modified: head/sys/kern/sys_generic.c ============================================================================== --- head/sys/kern/sys_generic.c Thu Feb 25 19:29:55 2016 (r296059) +++ head/sys/kern/sys_generic.c Thu Feb 25 19:58:23 2016 (r296060) @@ -1910,3 +1910,19 @@ selectinit(void *dummy __unused) NULL, NULL, UMA_ALIGN_PTR, 0); mtxpool_select = mtx_pool_create("select mtxpool", 128, MTX_DEF); } + +/* + * Set up a syscall return value that follows the convention specified for + * posix_* functions. + */ +int +kern_posix_error(struct thread *td, int error) +{ + + if (error <= 0) + return (error); + td->td_errno = error; + td->td_pflags |= TDP_NERRNO; + td->td_retval[0] = error; + return (0); +} Modified: head/sys/kern/vfs_syscalls.c ============================================================================== --- head/sys/kern/vfs_syscalls.c Thu Feb 25 19:29:55 2016 (r296059) +++ head/sys/kern/vfs_syscalls.c Thu Feb 25 19:58:23 2016 (r296060) @@ -4533,10 +4533,10 @@ kern_posix_fallocate(struct thread *td, int sys_posix_fallocate(struct thread *td, struct posix_fallocate_args *uap) { + int error; - td->td_retval[0] = kern_posix_fallocate(td, uap->fd, uap->offset, - uap->len); - return (0); + error = kern_posix_fallocate(td, uap->fd, uap->offset, uap->len); + return (kern_posix_error(td, error)); } /* @@ -4668,8 +4668,9 @@ out: int sys_posix_fadvise(struct thread *td, struct posix_fadvise_args *uap) { + int error; - td->td_retval[0] = kern_posix_fadvise(td, uap->fd, uap->offset, - uap->len, uap->advice); - return (0); + error = kern_posix_fadvise(td, uap->fd, uap->offset, uap->len, + uap->advice); + return (kern_posix_error(td, error)); } Modified: head/sys/sys/syscallsubr.h ============================================================================== --- head/sys/sys/syscallsubr.h Thu Feb 25 19:29:55 2016 (r296059) +++ head/sys/sys/syscallsubr.h Thu Feb 25 19:58:23 2016 (r296060) @@ -158,6 +158,7 @@ int kern_pipe(struct thread *td, int fil struct filecaps *fcaps1, struct filecaps *fcaps2); int kern_poll(struct thread *td, struct pollfd *fds, u_int nfds, struct timespec *tsp, sigset_t *uset); +int kern_posix_error(struct thread *td, int error); int kern_posix_fadvise(struct thread *td, int fd, off_t offset, off_t len, int advice); int kern_posix_fallocate(struct thread *td, int fd, off_t offset,