From owner-freebsd-fs@FreeBSD.ORG Thu Sep 23 23:27:00 2010 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3C201106564A for ; Thu, 23 Sep 2010 23:27:00 +0000 (UTC) (envelope-from markus.gebert@hostpoint.ch) Received: from mail.adm.hostpoint.ch (mail.adm.hostpoint.ch [217.26.48.124]) by mx1.freebsd.org (Postfix) with ESMTP id F16B98FC08 for ; Thu, 23 Sep 2010 23:26:59 +0000 (UTC) Received: from 46-127-29-79.dclient.hispeed.ch ([46.127.29.79]:47198 helo=[172.16.1.3]) by mail.adm.hostpoint.ch with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69 (FreeBSD)) (envelope-from ) id 1Oyv1A-0006bV-3t; Fri, 24 Sep 2010 01:15:56 +0200 Mime-Version: 1.0 (Apple Message framework v1081) Content-Type: text/plain; charset=us-ascii From: Markus Gebert In-Reply-To: <201009231938.09548.cal@linu.gs> Date: Fri, 24 Sep 2010 01:15:55 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <66757A1E-E445-4AAD-8F57-382D85BFD579@hostpoint.ch> References: <201009231938.09548.cal@linu.gs> To: Michael Naef X-Mailer: Apple Mail (2.1081) Cc: freebsd-fs Subject: Re: Strange behaviour with sappend flag set on ZFS X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Sep 2010 23:27:00 -0000 On 23.09.2010, at 19:38, Michael Naef wrote: > If I open (2) a file with O_APPEND the fd position pointer is set=20 > to the start of the file. When I then write to an fd on a ufs FS in=20 > FB6.4, it is automatically moved to the end and the bytes are=20 > appended. No problems appear with write to the sappend-flages file. >=20 > However if I do the same on FB8.1/ZFS, the write fails as "not=20 > permitted". To me, it seems that the zfs_write() VOP incorrectly uses FAPPEND = instead of IO_APPEND when checking the ioflag argument to see if the = current write is an appending one, here: ---- /* * If immutable or not appending then return EPERM */ pflags =3D zp->z_phys->zp_flags; if ((pflags & (ZFS_IMMUTABLE | ZFS_READONLY)) || ((pflags & ZFS_APPENDONLY) && !(ioflag & FAPPEND) && (uio->uio_loffset < zp->z_phys->zp_size))) { ZFS_EXIT(zfsvfs); return (EPERM); } ---- The function comment only mentions IO_APPEND and even later on in = zfs_write() IO_APPEND is used to check wether the offset should be = changed to EOF, so FAPPEND really seems to wrong in the above permission = check. CURRENT and STABLE-8 seem to be affected to. The following patch seems = to fix it (at least Michi's test case works fine with it): ---- diff -ru = ../src/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c = ./sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c --- ../src/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c = 2010-05-19 08:49:52.000000000 +0200 +++ ./sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c = 2010-09-23 23:24:43.549846948 +0200 @@ -709,7 +709,7 @@ */ pflags =3D zp->z_phys->zp_flags; if ((pflags & (ZFS_IMMUTABLE | ZFS_READONLY)) || - ((pflags & ZFS_APPENDONLY) && !(ioflag & FAPPEND) && + ((pflags & ZFS_APPENDONLY) && !(ioflag & IO_APPEND) && (uio->uio_loffset < zp->z_phys->zp_size))) { ZFS_EXIT(zfsvfs); return (EPERM); ---- Can someone commit this if the patch is ok? Or should I (or Michi) open = a PR? Markus