From patchwork Tue Feb 15 18:14:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 559331 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p1FIEn5A012135 for ; Tue, 15 Feb 2011 18:14:49 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755256Ab1BOSOq (ORCPT ); Tue, 15 Feb 2011 13:14:46 -0500 Received: from mail-fx0-f46.google.com ([209.85.161.46]:62403 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752266Ab1BOSOp (ORCPT ); Tue, 15 Feb 2011 13:14:45 -0500 Received: by fxm20 with SMTP id 20so460384fxm.19 for ; Tue, 15 Feb 2011 10:14:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:from:to:cc:subject:message-id:mime-version :content-type:content-disposition:user-agent; bh=DrcRaGtS7xrSLvxNNQH8oJPXffSJ7r4nlSc81JAlny4=; b=E3akoJtl4lbulPzsokJuXwKPqoytzRaaW6aKAsKjzJLkb6Pyosz08sawKVA8ETaNAs ZcqEJd8Wuf90jf8vkpam0QtrEg7HHo29kFIJEozQ+8/X2HGMu/tckLmjgSuwTbI36yHW AcnCvuDKxEGbEOjImgt+U1ab3OoVEhq4JJD80= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=ozxOhhpSSK/ANsJbuatTAeginpDUMM4Wg0T3qCjyavjZ5Wm4nQ6qMnS4BVBazw7vPp UrXbTBY/DdQrYUulxy3ysuxb3UvpkMaZKktda8IE1SqxY8ZC67cD3ZIpmWXzldqXr+Yn SB5VaR8EeDb2TGT+4L5TvScdTW+9ElKueNKMA= Received: by 10.223.83.208 with SMTP id g16mr6558446fal.52.1297793664117; Tue, 15 Feb 2011 10:14:24 -0800 (PST) Received: from localhost ([109.110.87.60]) by mx.google.com with ESMTPS id 17sm1810348far.19.2011.02.15.10.14.22 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 15 Feb 2011 10:14:23 -0800 (PST) Date: Tue, 15 Feb 2011 20:14:25 +0200 From: Ilya Dryomov To: linux-btrfs@vger.kernel.org Cc: Chris Mason Subject: [PATCH] Btrfs: make btrfs_rm_device() fail gracefully Message-ID: <20110215181425.GB9110@kwango.lan.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) 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.6 (demeter1.kernel.org [140.211.167.41]); Tue, 15 Feb 2011 18:14:49 +0000 (UTC) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index a228f63..172e0ad 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1338,11 +1338,11 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) ret = btrfs_shrink_device(device, 0); if (ret) - goto error_brelse; + goto error_undo; ret = btrfs_rm_dev_item(root->fs_info->chunk_root, device); if (ret) - goto error_brelse; + goto error_undo; device->in_fs_metadata = 0; @@ -1416,6 +1416,13 @@ out: mutex_unlock(&root->fs_info->volume_mutex); mutex_unlock(&uuid_mutex); return ret; +error_undo: + if (device->writeable) { + list_add(&device->dev_alloc_list, + &root->fs_info->fs_devices->alloc_list); + root->fs_info->fs_devices->rw_devices++; + } + goto error_brelse; } /*