From patchwork Sat Jun 12 22:31:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sage Weil X-Patchwork-Id: 105754 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5CMgECh015907 for ; Sat, 12 Jun 2010 22:42:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752738Ab0FLWmN (ORCPT ); Sat, 12 Jun 2010 18:42:13 -0400 Received: from cobra.newdream.net ([66.33.216.30]:54273 "EHLO cobra.newdream.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752578Ab0FLWmM (ORCPT ); Sat, 12 Jun 2010 18:42:12 -0400 Received: from localhost.localdomain (dsl092-035-022.lax1.dsl.speakeasy.net [66.92.35.22]) by cobra.newdream.net (Postfix) with ESMTPA id 13A33BC855; Sat, 12 Jun 2010 15:42:52 -0700 (PDT) From: Sage Weil To: linux-btrfs@vger.kernel.org Cc: Sage Weil Subject: [PATCH] Btrfs: fix CLONE ioctl destination file size expansion to block boundary Date: Sat, 12 Jun 2010 15:31:14 -0700 Message-Id: <1276381874-2964-1-git-send-email-sage@newdream.net> X-Mailer: git-send-email 1.7.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sat, 12 Jun 2010 22:42:15 +0000 (UTC) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 4cdb98c..a687f28 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1578,6 +1578,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, u64 disko = 0, diskl = 0; u64 datao = 0, datal = 0; u8 comp; + u64 endoff; size = btrfs_item_size_nr(leaf, slot); read_extent_buffer(leaf, buf, @@ -1712,9 +1713,18 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, btrfs_release_path(root, path); inode->i_mtime = inode->i_ctime = CURRENT_TIME; - if (new_key.offset + datal > inode->i_size) - btrfs_i_size_write(inode, - new_key.offset + datal); + + /* + * we round up to the block size at eof when + * determining which extents to clone above, + * but shouldn't round up the file size + */ + endoff = new_key.offset + datal; + if (endoff > off+olen) + endoff = off+olen; + if (endoff > inode->i_size) + btrfs_i_size_write(inode, endoff); + BTRFS_I(inode)->flags = BTRFS_I(src)->flags; ret = btrfs_update_inode(trans, root, inode); BUG_ON(ret);