From nobody@FreeBSD.org  Sat Apr 20 04:35:27 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115])
	by hub.freebsd.org (Postfix) with ESMTP id 8BF046E4
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 20 Apr 2013 04:35:27 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 7BAFFE53
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 20 Apr 2013 04:35:27 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r3K4ZRgt037318
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 20 Apr 2013 04:35:27 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id r3K4ZRlj037317;
	Sat, 20 Apr 2013 04:35:27 GMT
	(envelope-from nobody)
Message-Id: <201304200435.r3K4ZRlj037317@red.freebsd.org>
Date: Sat, 20 Apr 2013 04:35:27 GMT
From: Jon Valliere <sybersnake@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: disk usage problem when copying from one zfs dataset to another on the same pool using mv command
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         177985
>Category:       kern
>Synopsis:       [zfs] disk usage problem when copying from one zfs dataset to another on the same pool using mv command
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-fs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 20 04:40:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Sat Apr 20 20:30:00 UTC 2013
>Originator:     Jon Valliere
>Release:        8.3 < FreeNAS variant
>Organization:
>Environment:
FreeBSD freenas.local 8.3-RELEASE-p6 FreeBSD 8.3-RELEASE-p6 #0 r248141M: Sun Mar 10 16:35:05 PDT 2013     root@build.ixsystems.com:/home/jpaetzel/8.3.1-RELEASE/os-base/amd64/tank/home/jpaetzel/8.3.1-RELEASE/FreeBSD/src/sys/FREENAS.amd64  amd64
>Description:
the mv command performs a copy then delete operation when moving a file from one filesystem to another.

in freebsd zfs datasets are handled as independent file systems even tho they share the same logical disk pool much like dynamic partitioning, if you would.

for this given example I have a pool called array_0; array_0 has a total capacity of 4tb.

I have two datasets on array_0; stor and public.

stor has a folder FooBar which contains 3tb worth of files.

mv array_0/stor/FooBar array_0/public/FooBar

because these are different file systems it will copy then delete.

here is the problem.

there is only 1tb of space available on the pool.  there isn't enough space for a full copy.

today mv copied 1tb of data until the pool ran out of space then went kind of crazy.

obviously it was not deleting files after it had already copied as it went along.  if it had been deleting files as it was copying then it never would have totally consumed all disk space.
>How-To-Repeat:
create a pool with two datasets

create a some directory structure that represents 75% of total capacity.

mv that folder from one dataset to another on the same pool.
>Fix:
delete individual files after they are copied during the mv

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-fs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Apr 20 17:06:38 UTC 2013 
Responsible-Changed-Why:  

Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=177985 

From: "Steven Hartland" <smh@freebsd.org>
To: <bug-followup@freebsd.org>,
	<sybersnake@gmail.com>
Cc:  
Subject: Re: kern/177985: [zfs] disk usage problem when copying from one zfs dataset to another on the same pool using mv command
Date: Sat, 20 Apr 2013 18:30:26 +0100

 Deletes / frees are lower priority than standard writes / reads so its
 quite possible in the scenario you describe that you could run out of space.
 
 Could you please confirm the exact behaviour by allow mv to process a
 number of files, before suspending and seeing if the free space is correct
 for the current progress after waiting for the pool to sync all outstanding
 requests.
 
     Regards
     Steve

From: Andriy Gapon <avg@FreeBSD.org>
To: bug-followup@FreeBSD.org, sybersnake@gmail.com
Cc:  
Subject: Re: kern/177985: [zfs] disk usage problem when copying from one zfs
 dataset to another on the same pool using mv command
Date: Sat, 20 Apr 2013 22:12:12 +0300

 Sorry, but I do not see any bug reported here.
 mv behaves as it is expected/documented to behave.
 ZFS behaves as it should as well.
 If the behavior is surprising to you then please update your knowledge of the tools.
 If you need a different behavior then you can script it yourself or use
 different tools to accomplish your job.
 
 -- 
 Andriy Gapon

From: Jon <sybersnake@gmail.com>
To: Andriy Gapon <avg@FreeBSD.org>
Cc: "bug-followup@FreeBSD.org" <bug-followup@FreeBSD.org>
Subject: Re: kern/177985: [zfs] disk usage problem when copying from one zfs dataset to another on the same pool using mv command
Date: Sat, 20 Apr 2013 15:49:41 -0400

 This is not a bug, it is a workflow problem introduced by the difference in b=
 ehavior between ZFS datasets and fixed sized file systems.=20
 
 You should be able to move files from one dataset to another on the same poo=
 l without having to copy it to another pool and back. This all can be accomp=
 lished by deleting copied files more often than it currently does or at leas=
 t adding a flag to turn on synchronized deletes.
 
 After I am done testing the same scenario on Solaris I will run the test Ste=
 ve suggested.=20
 
 Sent from my iPhone
 
 On Apr 20, 2013, at 3:12 PM, Andriy Gapon <avg@FreeBSD.org> wrote:
 
 >=20
 > Sorry, but I do not see any bug reported here.
 > mv behaves as it is expected/documented to behave.
 > ZFS behaves as it should as well.
 > If the behavior is surprising to you then please update your knowledge of t=
 he tools.
 > If you need a different behavior then you can script it yourself or use
 > different tools to accomplish your job.
 >=20
 > --=20
 > Andriy Gapon

From: Andriy Gapon <avg@FreeBSD.org>
To: Jon <sybersnake@gmail.com>
Cc: "bug-followup@FreeBSD.org" <bug-followup@FreeBSD.org>
Subject: Re: kern/177985: [zfs] disk usage problem when copying from one zfs
 dataset to another on the same pool using mv command
Date: Sat, 20 Apr 2013 23:25:40 +0300

 on 20/04/2013 22:49 Jon said the following:
 > This is not a bug, it is a workflow problem introduced by the difference in
 > behavior between ZFS datasets and fixed sized file systems.
 > 
 > You should be able to move files from one dataset to another on the same pool
 > without having to copy it to another pool and back.
 
 You lost me at 'another pool'.
 
 Perhaps moving an object from one zfs dataset to another could be optimized,
 but...  That would definitely require zfs-specific tools.  It is not implemented
 in the code yet, as far as I know.
 
 > This all can be
 > accomplished by deleting copied files more often than it currently does or at
 > least adding a flag to turn on synchronized deletes.
 
 No, it can not be accomplished that way, because it would violate how mv(1)
 across filesystems works.  Perhaps it's indeed the time to read the man page?
 
 > After I am done testing the same scenario on Solaris I will run the test
 > Steve suggested.
 
 Yes, please do.  Personal experience is always more enlightening that someone
 else's words.
 
 > On Apr 20, 2013, at 3:12 PM, Andriy Gapon <avg@FreeBSD.org> wrote:
 > 
 >> 
 >> Sorry, but I do not see any bug reported here. mv behaves as it is
 >> expected/documented to behave. ZFS behaves as it should as well. If the
 >> behavior is surprising to you then please update your knowledge of the
 >> tools. If you need a different behavior then you can script it yourself or
 >> use different tools to accomplish your job.
 >> 
 >> -- Andriy Gapon
 
 
 -- 
 Andriy Gapon
>Unformatted:
