From owner-freebsd-fs@FreeBSD.ORG Wed Jan 2 22:07:33 2013 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 6E0FFCBE for ; Wed, 2 Jan 2013 22:07:33 +0000 (UTC) (envelope-from longwitz@incore.de) Received: from dss.incore.de (dss.incore.de [195.145.1.138]) by mx1.freebsd.org (Postfix) with ESMTP id 3444D757 for ; Wed, 2 Jan 2013 22:07:32 +0000 (UTC) Received: from inetmail.dmz (inetmail.dmz [10.3.0.3]) by dss.incore.de (Postfix) with ESMTP id 88D925C4AF for ; Wed, 2 Jan 2013 23:07:26 +0100 (CET) X-Virus-Scanned: amavisd-new at incore.de Received: from dss.incore.de ([10.3.0.3]) by inetmail.dmz (inetmail.dmz [10.3.0.3]) (amavisd-new, port 10024) with LMTP id zynOMpcDheNn for ; Wed, 2 Jan 2013 23:07:25 +0100 (CET) Received: from mail.incore (fwintern.dmz [10.0.0.253]) by dss.incore.de (Postfix) with ESMTP id A6C8F5C4AE for ; Wed, 2 Jan 2013 23:07:25 +0100 (CET) Received: from bsdmhs.longwitz (unknown [192.168.99.6]) by mail.incore (Postfix) with ESMTP id 4B1825083F for ; Wed, 2 Jan 2013 23:07:25 +0100 (CET) Message-ID: <50E4AF9C.9060404@incore.de> Date: Wed, 02 Jan 2013 23:07:24 +0100 From: Andreas Longwitz User-Agent: Thunderbird 2.0.0.19 (X11/20090113) MIME-Version: 1.0 To: freebsd-fs@freebsd.org Subject: g_journal_ufs_using_last_sector() needs minor correction (patch included) Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jan 2013 22:07:33 -0000 On a testdisk created with dd if=/dev/zero of=diskfile count=5000 bs=1m mdconfig -a -t vnode -f diskfile -u 1 let us create a mirrored and gjournaled filesystem: gmirror label -b prefer -F gmX md1 gpart create -s GPT mirror/gmX gpart add -t freebsd-swap -s 4194304 -i 1 mirror/gmX gpart add -t freebsd-ufs -i 2 mirror/gmX gjournal label mirror/gmXp2 mirror/gmXp1 newfs -J /dev/mirror/gmXp2.journal mount /dev/mirror/gmXp2.journal /mnt ... put some data to /mnt umount /mnt The mediasizes in sectors for gjournal consumer and provider: diskinfo /dev/mirror/gmXp2.journal --> /dev/mirror/gmXp2.journal 512 3095361024 6045627 0 0 dumpfs -m /dev/mirror/gmXp2.journal --> # newfs command for /dev/mirror/gmXp2.journal newfs -O 2 -J -a 8 -b 16384 -d 16384 -e 2048 -f 2048 -g 16384 -h 64 -m 8 -o time -s 6045624 /dev/mirror/gmXp2.journal The size of the created filesystem is 6045624 and three blocks less than the size gjournal provides. Now I had the need to rename gmX to gmY without loosing my data: gjournal stop mirror/gmXp2.journal gjournal clear mirror/gmXp2 gjournal clear mirror/gmXp1 gpart delete -i 1 mirror/gmX gpart delete -i 2 mirror/gmX gpart destroy mirror/gmX gmirror stop gmX gmirror clear /dev/md1 gmirror label -b prefer -F gmY md1 gpart create -s GPT mirror/gmY gpart add -t freebsd-swap -s 4194304 -i 1 mirror/gmY gpart add -t freebsd-ufs -i 2 mirror/gmY gjournal label mirror/gmYp2 mirror/gmYp1 At this point gjournal gives the unjustified error message "File system on mirror/gmYp2 is using the last sector and this operation is going to overwrite it. Use -f if you really want to do it." the reason for this is an improper size check in the function g_journal_ufs_using_last_sector() which can be corrected by the following patch: --- geom_journal_ufs.c.orig 2009-08-03 10:13:06.000000000 +0200 +++ geom_journal_ufs.c 2013-01-02 23:01:37.000000000 +0100 @@ -73,6 +73,6 @@ /* Provider size in 512 bytes blocks. */ psize = g_get_mediasize(prov) / DEV_BSIZE; /* File system size in 512 bytes blocks. */ - fssize = fsbtodb(fs, dbtofsb(fs, psize)); - return (psize == fssize); + fssize = fsbtodb(fs, fs->fs_size); + return (psize <= fssize); } -- Andreas Longwitz