From patchwork Thu Mar 7 21:38:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mitch Harder X-Patchwork-Id: 2233711 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 4587F3FCF6 for ; Thu, 7 Mar 2013 21:39:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759801Ab3CGVjD (ORCPT ); Thu, 7 Mar 2013 16:39:03 -0500 Received: from mail-oa0-f44.google.com ([209.85.219.44]:60782 "EHLO mail-oa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758727Ab3CGVjA convert rfc822-to-8bit (ORCPT ); Thu, 7 Mar 2013 16:39:00 -0500 Received: by mail-oa0-f44.google.com with SMTP id h1so1234371oag.31 for ; Thu, 07 Mar 2013 13:39:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:content-transfer-encoding :x-gm-message-state; bh=/KucbSVdRpxOrHumIT3QLylcqpqpneP1KRo3WeK5qfs=; b=hzUjFMpVzCcMuy/mVfZpoSLRWSB5fKa7WUL0bH4I17F96rQ9iSfMjgW99SzvTHzL8d pGKUAYxdlYZNamAiFhxO8cT4epel4ZLORp0p59gXmJhlY9xG0r6LjuB1vtflQtLHMwxD FzHJH4d+Zu2vAr9mS1tzdpINH+bl5LOckL1xQyQlzbRJUDQjTSK+0wfS250+F6zeh9NT XyJhnv0dH9i3NPSGxxDE45OMDKaX59V9xu7sONqj0ASlg0AiJQRj3GAesNb+qfYuWaAL +CkM4Z27sT1b5qwmCo9QBJ9xRx+gSwCh61YRTXzTGP8tuI4IO0n/K61gC+ULBvZrunig /55g== MIME-Version: 1.0 X-Received: by 10.60.5.165 with SMTP id t5mr27700362oet.117.1362692340109; Thu, 07 Mar 2013 13:39:00 -0800 (PST) Received: by 10.60.56.132 with HTTP; Thu, 7 Mar 2013 13:38:59 -0800 (PST) In-Reply-To: <5138D80F.1080304@petaramesh.org> References: <513883DD.8080203@petaramesh.org> <5138980C.8080000@redhat.com> <5138ADA6.5070101@petaramesh.org> <5138AE96.3020304@redhat.com> <5138B08F.70607@petaramesh.org> <5138D80F.1080304@petaramesh.org> Date: Thu, 7 Mar 2013 15:38:59 -0600 Message-ID: Subject: Re: mkfs.btrfs broken From: Mitch Harder To: =?ISO-8859-1?Q?Sw=E2mi_Petaramesh?= Cc: =?ISO-8859-1?Q?J=E9r=F4me_Poulin?= , Eric Sandeen , "BTRFS, Linux" , Anand Jain X-Gm-Message-State: ALoCoQmJJBh4UFZCAZKyqq1eECbn6mshbHjXZtkDZGkQVLliK28vc/lhCCZdowpERREladdLAIVo Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On Thu, Mar 7, 2013 at 12:10 PM, Swâmi Petaramesh wrote: > Le 07/03/2013 19:06, Jérôme Poulin a écrit : >> mkfs.btrfs tries to lookup loop devices by their filenames and fails >> if any loop device file is missing. > > Hmm.... Why would mkfs.btrfs want to lookup anything else but the device > we're trying to format, to check if it's mounted or not ? > At Sabayon, we pretty-much hacked our way around this with a "make-it-go" kind of patch. Otherwise, our installation would break with btrfs on our Live-[CD/DVD/USB] media. I know we should have taken the time to put together a proper solution, but I could never figure out the reasoning for needing to scan every device either. --- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- btrfs-progs-0.19.orig/utils.c +++ btrfs-progs-0.19/utils.c @@ -708,6 +708,21 @@ int is_same_blk_file(const char* a, cons return 0; } +/* Checks if a file exists and is a block or regular file*/ +int is_existing_blk_or_reg_file(const char* filename) +{ + struct stat st_buf; + + if(stat(filename, &st_buf) < 0) { + if(errno == ENOENT) + return 0; + else + return -errno; + } + + return (S_ISBLK(st_buf.st_mode) || S_ISREG(st_buf.st_mode)); +} + /* checks if a and b are identical or device * files associated with the same block device or * if one file is a loop device that uses the other @@ -727,7 +742,10 @@ int is_same_loop_file(const char* a, con } else if(ret) { if((ret = resolve_loop_device(a, res_a, sizeof(res_a))) < 0) return ret; - + /* if the resolved path is not available, there is nothing + we can do */ + if((ret = is_existing_blk_or_reg_file(res_a)) == 0) + return ret; final_a = res_a; } else { final_a = a; @@ -739,6 +757,10 @@ int is_same_loop_file(const char* a, con } else if(ret) { if((ret = resolve_loop_device(b, res_b, sizeof(res_b))) < 0) return ret; + /* if the resolved path is not available, there is nothing + we can do */ + if((ret = is_existing_blk_or_reg_file(res_b)) == 0) + return ret; final_b = res_b; } else { @@ -748,21 +770,6 @@ int is_same_loop_file(const char* a, con return is_same_blk_file(final_a, final_b); } -/* Checks if a file exists and is a block or regular file*/ -int is_existing_blk_or_reg_file(const char* filename) -{ - struct stat st_buf; - - if(stat(filename, &st_buf) < 0) { - if(errno == ENOENT) - return 0; - else - return -errno; - } - - return (S_ISBLK(st_buf.st_mode) || S_ISREG(st_buf.st_mode)); -} - /* Checks if a file is used (directly or indirectly via a loop device) * by a device in fs_devices */