From owner-svn-src-projects@freebsd.org Tue Sep 3 14:06:04 2019 Return-Path: Delivered-To: svn-src-projects@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2181BDC1D8 for ; Tue, 3 Sep 2019 14:06:01 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [96.47.72.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46N7yw3jHwz4P5c; Tue, 3 Sep 2019 14:06:00 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1452) id 545CE19F8E; Tue, 3 Sep 2019 14:05:54 +0000 (UTC) X-Original-To: yuripv@localmail.freebsd.org Delivered-To: yuripv@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id EE336D0EC; Mon, 1 Apr 2019 14:23:47 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D99571292; Mon, 1 Apr 2019 14:23:47 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 538) id 1A1A4D07F; Mon, 1 Apr 2019 14:23:47 +0000 (UTC) Delivered-To: src-committers@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 990B3D077 for ; Mon, 1 Apr 2019 14:23:44 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6A86671284; Mon, 1 Apr 2019 14:23:44 +0000 (UTC) (envelope-from asomers@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 44DADFA83; Mon, 1 Apr 2019 14:23:44 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x31ENii4045853; Mon, 1 Apr 2019 14:23:44 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x31ENhtx045849; Mon, 1 Apr 2019 14:23:43 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201904011423.x31ENhtx045849@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r345766 - projects/fuse2/sys/fs/fuse X-SVN-Group: projects X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: projects/fuse2/sys/fs/fuse X-SVN-Commit-Revision: 345766 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk X-Loop: FreeBSD.org Sender: owner-src-committers@freebsd.org X-Rspamd-Queue-Id: 4D99571292 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.997,0]; NEURAL_HAM_SHORT(-0.95)[-0.951,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] Status: O X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.29 List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Tue, 03 Sep 2019 14:06:04 -0000 X-Original-Date: Mon, 1 Apr 2019 14:23:43 +0000 (UTC) X-List-Received-Date: Tue, 03 Sep 2019 14:06:04 -0000 Author: asomers Date: Mon Apr 1 14:23:43 2019 New Revision: 345766 URL: https://svnweb.freebsd.org/changeset/base/345766 Log: fusefs: replace obsolete array idioms r345742 replaced fusefs's fufh array with a fufh list. But it left a few array idioms in place. This commit replaces those idioms with more efficient list idioms. One location is in fuse_filehandle_close, which now takes a pointer argument. Three other locations are places that had to loop over all of a vnode's fuse filehandles. Sponsored by: The FreeBSD Foundation Modified: projects/fuse2/sys/fs/fuse/fuse_file.c projects/fuse2/sys/fs/fuse/fuse_file.h projects/fuse2/sys/fs/fuse/fuse_internal.c projects/fuse2/sys/fs/fuse/fuse_vnops.c Modified: projects/fuse2/sys/fs/fuse/fuse_file.c ============================================================================== --- projects/fuse2/sys/fs/fuse/fuse_file.c Mon Apr 1 14:21:32 2019 (r345765) +++ projects/fuse2/sys/fs/fuse/fuse_file.c Mon Apr 1 14:23:43 2019 (r345766) @@ -154,21 +154,15 @@ out: } int -fuse_filehandle_close(struct vnode *vp, fufh_type_t fufh_type, +fuse_filehandle_close(struct vnode *vp, struct fuse_filehandle *fufh, struct thread *td, struct ucred *cred) { struct fuse_dispatcher fdi; struct fuse_release_in *fri; - struct fuse_filehandle *fufh = NULL; int err = 0; int op = FUSE_RELEASE; - if (fuse_filehandle_get(vp, fufh_type, &fufh)) { - panic("FUSE: fuse_filehandle_close called on invalid fufh " - "(type=%d)", fufh_type); - /* NOTREACHED */ - } if (fuse_isdeadfs(vp)) { goto out; } @@ -178,7 +172,7 @@ fuse_filehandle_close(struct vnode *vp, fufh_type_t fu fdisp_make_vp(&fdi, op, vp, td, cred); fri = fdi.indata; fri->fh = fufh->fh_id; - fri->flags = fuse_filehandle_xlate_to_oflags(fufh_type); + fri->flags = fufh->flags; err = fdisp_wait_answ(&fdi); fdisp_destroy(&fdi); @@ -221,10 +215,10 @@ fuse_filehandle_get(struct vnode *vp, fufh_type_t fufh struct fuse_vnode_data *fvdat = VTOFUD(vp); struct fuse_filehandle *fufh; - /* TODO: Find a list entry with the same mode, pid, gid, and uid */ - /* Fallback: find a list entry with the right mode */ + /* TODO: Find a list entry with the same flags, pid, gid, and uid */ + /* Fallback: find a list entry with the right flags */ LIST_FOREACH(fufh, &fvdat->handles, next) { - if (fufh->mode == fufh_type) + if (fufh->flags == fufh_type) break; } @@ -258,7 +252,7 @@ fuse_filehandle_init(struct vnode *vp, fufh_type_t fuf M_WAITOK); MPASS(fufh != NULL); fufh->fh_id = fh_id; - fufh->mode = fufh_type; + fufh->flags = fufh_type; /* TODO: initialize fufh credentials and open flags */ if (!FUFH_IS_VALID(fufh)) { panic("FUSE: init: invalid filehandle id (type=%d)", fufh_type); Modified: projects/fuse2/sys/fs/fuse/fuse_file.h ============================================================================== --- projects/fuse2/sys/fs/fuse/fuse_file.h Mon Apr 1 14:21:32 2019 (r345765) +++ projects/fuse2/sys/fs/fuse/fuse_file.h Mon Apr 1 14:23:43 2019 (r345766) @@ -66,12 +66,16 @@ #include #include +/* + * The fufh type is the access mode of the fuse file handle. It's the portion + * of the open(2) flags related to permission. + */ typedef enum fufh_type { FUFH_INVALID = -1, FUFH_RDONLY = 0, FUFH_WRONLY = 1, FUFH_RDWR = 2, - FUFH_MAXTYPE = 3, + /* TODO: add FUFH_EXEC */ } fufh_type_t; _Static_assert(FUFH_RDONLY == O_RDONLY, "RDONLY"); _Static_assert(FUFH_WRONLY == O_WRONLY, "WRONLY"); @@ -86,8 +90,8 @@ struct fuse_filehandle { /* flags returned by FUSE_OPEN */ uint32_t fuse_open_flags; - /* The mode used to open(2) the file (using O_RDONLY, not FREAD) */ - uint32_t mode; + /* The flags used to open(2) the file (using O_RDONLY, not FREAD) */ + uint32_t flags; /* Credentials used to open the file */ gid_t gid; @@ -95,7 +99,7 @@ struct fuse_filehandle { uid_t uid; }; -#define FUFH_IS_VALID(f) ((f)->mode != FUFH_INVALID) +#define FUFH_IS_VALID(f) ((f)->flags != FUFH_INVALID) static inline fufh_type_t fuse_filehandle_xlate_from_fflags(int fflags) @@ -140,7 +144,7 @@ void fuse_filehandle_init(struct vnode *vp, fufh_type_ int fuse_filehandle_open(struct vnode *vp, fufh_type_t fufh_type, struct fuse_filehandle **fufhp, struct thread *td, struct ucred *cred); -int fuse_filehandle_close(struct vnode *vp, fufh_type_t fufh_type, +int fuse_filehandle_close(struct vnode *vp, struct fuse_filehandle *fufh, struct thread *td, struct ucred *cred); #endif /* _FUSE_FILE_H_ */ Modified: projects/fuse2/sys/fs/fuse/fuse_internal.c ============================================================================== --- projects/fuse2/sys/fs/fuse/fuse_internal.c Mon Apr 1 14:21:32 2019 (r345765) +++ projects/fuse2/sys/fs/fuse/fuse_internal.c Mon Apr 1 14:23:43 2019 (r345766) @@ -285,36 +285,37 @@ fuse_internal_fsync(struct vnode *vp, struct fuse_fsync_in *ffsi; struct fuse_dispatcher fdi; struct fuse_filehandle *fufh; + struct fuse_vnode_data *fvdat = VTOFUD(vp); int op = FUSE_FSYNC; - int type = 0; int err = 0; if (!fsess_isimpl(vnode_mount(vp), (vnode_vtype(vp) == VDIR ? FUSE_FSYNCDIR : FUSE_FSYNC))) { return 0; } - for (type = 0; type < FUFH_MAXTYPE; type++) { - if (fuse_filehandle_get(vp, type, &fufh) == 0) { - if (vnode_isdir(vp)) { - op = FUSE_FSYNCDIR; - } - fdisp_init(&fdi, sizeof(*ffsi)); - fdisp_make_vp(&fdi, op, vp, td, NULL); - ffsi = fdi.indata; - ffsi->fh = fufh->fh_id; + if (vnode_isdir(vp)) + op = FUSE_FSYNCDIR; + /* + * fsync every open file handle for this file, because we can't be sure + * which file handle the caller is really referring to. + */ + LIST_FOREACH(fufh, &fvdat->handles, next) { + fdisp_init(&fdi, sizeof(*ffsi)); + fdisp_make_vp(&fdi, op, vp, td, NULL); + ffsi = fdi.indata; + ffsi->fh = fufh->fh_id; - if (datasync) - ffsi->fsync_flags = 1; + if (datasync) + ffsi->fsync_flags = 1; - if (waitfor == MNT_WAIT) { - err = fdisp_wait_answ(&fdi); - } else { - fuse_insert_callback(fdi.tick, - fuse_internal_fsync_callback); - fuse_insert_message(fdi.tick); - } - fdisp_destroy(&fdi); + if (waitfor == MNT_WAIT) { + err = fdisp_wait_answ(&fdi); + } else { + fuse_insert_callback(fdi.tick, + fuse_internal_fsync_callback); + fuse_insert_message(fdi.tick); } + fdisp_destroy(&fdi); } return err; Modified: projects/fuse2/sys/fs/fuse/fuse_vnops.c ============================================================================== --- projects/fuse2/sys/fs/fuse/fuse_vnops.c Mon Apr 1 14:21:32 2019 (r345765) +++ projects/fuse2/sys/fs/fuse/fuse_vnops.c Mon Apr 1 14:23:43 2019 (r345766) @@ -278,33 +278,22 @@ fuse_vnop_close(struct vop_close_args *ap) struct vnode *vp = ap->a_vp; struct ucred *cred = ap->a_cred; int fflag = ap->a_fflag; - fufh_type_t fufh_type; if (fuse_isdeadfs(vp)) { return 0; } if (vnode_isdir(vp)) { - if (fuse_filehandle_valid(vp, FUFH_RDONLY)) { - fuse_filehandle_close(vp, FUFH_RDONLY, NULL, cred); + struct fuse_filehandle *fufh; + + if (fuse_filehandle_get(vp, O_RDONLY, &fufh)) { + fuse_filehandle_close(vp, fufh, NULL, cred); } return 0; } if (fflag & IO_NDELAY) { return 0; } - fufh_type = fuse_filehandle_xlate_from_fflags(fflag); - - if (!fuse_filehandle_valid(vp, fufh_type)) { - int i; - - for (i = 0; i < FUFH_MAXTYPE; i++) - if (fuse_filehandle_valid(vp, i)) - break; - if (i == FUFH_MAXTYPE) - panic("FUSE: fufh type %d found to be invalid in close" - " (fflag=0x%x)\n", - fufh_type, fflag); - } + /* TODO: close the file handle, if we're sure it's no longer used */ if ((VTOFUD(vp)->flag & FN_SIZECHANGE) != 0) { fuse_vnode_savesize(vp, cred); } @@ -601,25 +590,23 @@ fuse_vnop_inactive(struct vop_inactive_args *ap) struct thread *td = ap->a_td; struct fuse_vnode_data *fvdat = VTOFUD(vp); - struct fuse_filehandle *fufh = NULL; + struct fuse_filehandle *fufh, *fufh_tmp; - int type, need_flush = 1; + int need_flush = 1; - for (type = 0; type < FUFH_MAXTYPE; type++) { - if (!fuse_filehandle_get(vp, type, &fufh)) { - if (need_flush && vp->v_type == VREG) { - if ((VTOFUD(vp)->flag & FN_SIZECHANGE) != 0) { - fuse_vnode_savesize(vp, NULL); - } - if (fuse_data_cache_invalidate || - (fvdat->flag & FN_REVOKED) != 0) - fuse_io_invalbuf(vp, td); - else - fuse_io_flushbuf(vp, MNT_WAIT, td); - need_flush = 0; + LIST_FOREACH_SAFE(fufh, &fvdat->handles, next, fufh_tmp) { + if (need_flush && vp->v_type == VREG) { + if ((VTOFUD(vp)->flag & FN_SIZECHANGE) != 0) { + fuse_vnode_savesize(vp, NULL); } - fuse_filehandle_close(vp, type, td, NULL); + if (fuse_data_cache_invalidate || + (fvdat->flag & FN_REVOKED) != 0) + fuse_io_invalbuf(vp, td); + else + fuse_io_flushbuf(vp, MNT_WAIT, td); + need_flush = 0; } + fuse_filehandle_close(vp, fufh, td, NULL); } if ((fvdat->flag & FN_REVOKED) != 0 && fuse_reclaim_revoked) { @@ -1317,13 +1304,11 @@ fuse_vnop_readdir(struct vop_readdir_args *ap) return EINVAL; } - if (!fuse_filehandle_valid(vp, FUFH_RDONLY)) { + if ((err = fuse_filehandle_get(vp, O_RDONLY, &fufh)) != 0) { SDT_PROBE2(fuse, , vnops, trace, 1, "calling readdir() before open()"); - err = fuse_filehandle_open(vp, FUFH_RDONLY, &fufh, NULL, cred); + err = fuse_filehandle_open(vp, O_RDONLY, &fufh, NULL, cred); freefufh = 1; - } else { - err = fuse_filehandle_get(vp, FUFH_RDONLY, &fufh); } if (err) { return (err); @@ -1334,9 +1319,9 @@ fuse_vnop_readdir(struct vop_readdir_args *ap) err = fuse_internal_readdir(vp, uio, fufh, &cookediov); fiov_teardown(&cookediov); - if (freefufh) { - fuse_filehandle_close(vp, FUFH_RDONLY, NULL, cred); - } + if (freefufh) + fuse_filehandle_close(vp, fufh, NULL, cred); + return err; } @@ -1393,20 +1378,16 @@ fuse_vnop_reclaim(struct vop_reclaim_args *ap) { struct vnode *vp = ap->a_vp; struct thread *td = ap->a_td; - struct fuse_vnode_data *fvdat = VTOFUD(vp); + struct fuse_filehandle *fufh, *fufh_tmp; - int type; - if (!fvdat) { panic("FUSE: no vnode data during recycling"); } - for (type = 0; type < FUFH_MAXTYPE; type++) { - if (fuse_filehandle_get(vp, type, NULL) == 0) { - printf("FUSE: vnode being reclaimed but fufh (type=%d) is valid", - type); - fuse_filehandle_close(vp, type, td, NULL); - } + LIST_FOREACH_SAFE(fufh, &fvdat->handles, next, fufh_tmp) { + printf("FUSE: vnode being reclaimed with open fufh " + "(flags=%#x)", fufh->flags); + fuse_filehandle_close(vp, fufh, td, NULL); } if ((!fuse_isdeadfs(vp)) && (fvdat->nlookup)) {