From owner-svn-src-projects@freebsd.org Thu May 16 22:50:06 2019 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0112115A92D9 for ; Thu, 16 May 2019 22:50:06 +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 8D68277CD8; Thu, 16 May 2019 22:50:05 +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 68974276A4; Thu, 16 May 2019 22:50:05 +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 x4GMo5CL077099; Thu, 16 May 2019 22:50:05 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x4GMo5TO077096; Thu, 16 May 2019 22:50:05 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201905162250.x4GMo5TO077096@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Thu, 16 May 2019 22:50:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r347897 - in projects/fuse2: sys/fs/fuse tests/sys/fs/fusefs X-SVN-Group: projects X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: in projects/fuse2: sys/fs/fuse tests/sys/fs/fusefs X-SVN-Commit-Revision: 347897 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 8D68277CD8 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_SHORT(-0.98)[-0.976,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 May 2019 22:50:06 -0000 Author: asomers Date: Thu May 16 22:50:04 2019 New Revision: 347897 URL: https://svnweb.freebsd.org/changeset/base/347897 Log: fusefs: allow the server to specify st_blksize If the server sets fuse_attr.blksize to a nonzero value in the response to FUSE_GETATTR, then the client should use that as the value for stat.st_blksize . Sponsored by: The FreeBSD Foundation Modified: projects/fuse2/sys/fs/fuse/fuse_internal.c projects/fuse2/tests/sys/fs/fusefs/getattr.cc Modified: projects/fuse2/sys/fs/fuse/fuse_internal.c ============================================================================== --- projects/fuse2/sys/fs/fuse/fuse_internal.c Thu May 16 22:27:38 2019 (r347896) +++ projects/fuse2/sys/fs/fuse/fuse_internal.c Thu May 16 22:50:04 2019 (r347897) @@ -198,10 +198,12 @@ fuse_internal_cache_attrs(struct vnode *vp, struct fus { struct mount *mp; struct fuse_vnode_data *fvdat; + struct fuse_data *data; struct vattr *vp_cache_at; mp = vnode_mount(vp); fvdat = VTOFUD(vp); + data = fuse_get_mpdata(mp); fuse_validity_2_bintime(attr_valid, attr_valid_nsec, &fvdat->attr_cache_timeout); @@ -231,7 +233,10 @@ fuse_internal_cache_attrs(struct vnode *vp, struct fus vap->va_mtime.tv_nsec = attr->mtimensec; vap->va_ctime.tv_sec = attr->ctime; vap->va_ctime.tv_nsec = attr->ctimensec; - vap->va_blocksize = PAGE_SIZE; + if (fuse_libabi_geq(data, 7, 9) && attr->blksize > 0) + vap->va_blocksize = attr->blksize; + else + vap->va_blocksize = PAGE_SIZE; vap->va_type = IFTOVT(attr->mode); vap->va_bytes = attr->blocks * S_BLKSIZE; vap->va_flags = 0; Modified: projects/fuse2/tests/sys/fs/fusefs/getattr.cc ============================================================================== --- projects/fuse2/tests/sys/fs/fusefs/getattr.cc Thu May 16 22:27:38 2019 (r347896) +++ projects/fuse2/tests/sys/fs/fusefs/getattr.cc Thu May 16 22:50:04 2019 (r347897) @@ -28,6 +28,10 @@ * SUCH DAMAGE. */ +extern "C" { +#include +} + #include "mockfs.hh" #include "utils.hh" @@ -130,6 +134,35 @@ TEST_F(Getattr, attr_cache_timeout) EXPECT_EQ(0, stat(FULLPATH, &sb)); } +/* + * If attr.blksize is zero, then the kernel should use a default value for + * st_blksize + */ +TEST_F(Getattr, blksize_zero) +{ + const char FULLPATH[] = "mountpoint/some_file.txt"; + const char RELPATH[] = "some_file.txt"; + const uint64_t ino = 42; + struct stat sb; + + expect_lookup(RELPATH, ino, S_IFREG | 0644, 1, 1, 0, 0); + EXPECT_CALL(*m_mock, process( + ResultOf([](auto in) { + return (in->header.opcode == FUSE_GETATTR && + in->header.nodeid == ino); + }, Eq(true)), + _) + ).WillOnce(Invoke(ReturnImmediate([](auto i __unused, auto out) { + SET_OUT_HEADER_LEN(out, attr); + out->body.attr.attr.mode = S_IFREG | 0644; + out->body.attr.attr.ino = ino; // Must match nodeid + out->body.attr.attr.blksize = 0; + }))); + + ASSERT_EQ(0, stat(FULLPATH, &sb)) << strerror(errno); + EXPECT_EQ((blksize_t)PAGE_SIZE, sb.st_blksize); +} + TEST_F(Getattr, enoent) { const char FULLPATH[] = "mountpoint/some_file.txt"; @@ -179,6 +212,7 @@ TEST_F(Getattr, ok) out->body.attr.attr.uid = 10; out->body.attr.attr.gid = 11; out->body.attr.attr.rdev = 12; + out->body.attr.attr.blksize = 12345; }))); ASSERT_EQ(0, stat(FULLPATH, &sb)) << strerror(errno); @@ -194,6 +228,7 @@ TEST_F(Getattr, ok) EXPECT_EQ(10ul, sb.st_uid); EXPECT_EQ(11ul, sb.st_gid); EXPECT_EQ(12ul, sb.st_rdev); + EXPECT_EQ((blksize_t)12345, sb.st_blksize); EXPECT_EQ(ino, sb.st_ino); EXPECT_EQ(S_IFREG | 0644, sb.st_mode);