Received: from list by lists.gnu.org with archive (Exim 4.71) id 1fJ1TZ-0000CQ-Nl for mharc-grub-devel@gnu.org; Wed, 16 May 2018 14:48:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJ1TT-00007j-W3 for grub-devel@gnu.org; Wed, 16 May 2018 14:48:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJ1TT-0006uZ-2H for grub-devel@gnu.org; Wed, 16 May 2018 14:48:32 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:54370) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fJ1TS-0006uI-NP for grub-devel@gnu.org; Wed, 16 May 2018 14:48:30 -0400 Received: by mail-wm0-x243.google.com with SMTP id f6-v6so3837443wmc.4 for ; Wed, 16 May 2018 11:48:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mcku9824yQuHdn/YawYDYXeiC6J/mYLNt2Y8VZngSLw=; b=QTIwZ8EfblGWoNyZF8gALcMo5+TdToCinZtlIHoU6YTbU5I5UReJQPfP5TDGzCkv8h oCplgaRSjtzfFjnxa+Yrj/VniUCFEk4F65rXXdijCo9VtHyigOKturQXeKcA3CWWVgkb VhDIBHfDBWuEiABJ6O/g22o7srGMmgq9ylIjA3niX2czMqxqieYBawnGG8zgQE8QGRmf N5xZq4OELSesUVa7+/l7RsB8lJTSDHGe39Au80TAnOx491J9ikSAdEdz39EDZ9IZ1KkM Q0ADX54Q42/FKCAczSCezbRwkBRLIR+m5Nyg8jjCYqfh7O/BELu49Lv3hjwZyxaS6xNu yWrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mcku9824yQuHdn/YawYDYXeiC6J/mYLNt2Y8VZngSLw=; b=oba8GzMSfXt+Qa5JuOQRxN9lJaSRamZ59eHOf7qzSuHg0cedf0gKAc/lGgK4xVUjNV btxowkr1CX38iegsoIxs28CrqTvbN71yOzEeNCmwcNeKBSTaqmUECz8aGkEUr2nNxufi zP7HjH3dzr6PmACL1ntD91NcbcmMtSHKbe6Vl64s/ihsWURXe6PpNhMERx9pYIiLNXhN ec5G9AMK5LajnVs1HWNjlWbpmwIBmGA5iKEUvmo6M6bwfI5NDyg6lCOFFwV46hyCep5Z NyoXH4plGIXg0ZYOBm3Obd42/Y6/bvWRl5eixNsutbLO+EK2m84sEXcUbcyIMLiyJlMz d+8g== X-Gm-Message-State: ALKqPwdlUEH10g7JUr1409TzQvC9qk9lj15ZjsaQmfy1nyCPCRw9JLNr uV9YK7FWRvlqx67A/nXiPdqYpQ== X-Google-Smtp-Source: AB8JxZqQY8ksqSUa+5vsikwdwahWqnuG2XUec2LVrjoFAUySao4gCnVVMtfbALa4+kRGDfbzURxCGA== X-Received: by 2002:a1c:63c5:: with SMTP id x188-v6mr1568212wmb.61.1526496509430; Wed, 16 May 2018 11:48:29 -0700 (PDT) Received: from venice.bhome (94-38-2-55.adsl-ull.clienti.tiscali.it. [94.38.2.55]) by smtp.gmail.com with ESMTPSA id d17-v6sm3797129wrc.0.2018.05.16.11.48.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 May 2018 11:48:29 -0700 (PDT) From: Goffredo Baroncelli X-Google-Original-From: Goffredo Baroncelli To: grub-devel@gnu.org Cc: Goffredo Baroncelli Subject: [PATCH 4/9] btrfs: avoiding a rescan for a device which was already not founded. Date: Wed, 16 May 2018 20:48:14 +0200 Message-Id: <20180516184819.23736-5-kreijack@inwind.it> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180516184819.23736-1-kreijack@inwind.it> References: <20180516184819.23736-1-kreijack@inwind.it> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::243 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 May 2018 18:48:33 -0000 If a device is not found, record this failure storing NULL in data->devices_attached[]. This avoid un-necessary devices rescan, speeding the reading in case of a degraded array. Signed-off-by: Goffredo Baroncelli --- grub-core/fs/btrfs.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index fd4225d11..4920dd3b1 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -588,7 +588,7 @@ find_device_iter (const char *name, void *data) } static grub_device_t -find_device (struct grub_btrfs_data *data, grub_uint64_t id, int do_rescan) +find_device (struct grub_btrfs_data *data, grub_uint64_t id) { struct find_device_ctx ctx = { .data = data, @@ -600,12 +600,9 @@ find_device (struct grub_btrfs_data *data, grub_uint64_t id, int do_rescan) for (i = 0; i < data->n_devices_attached; i++) if (id == data->devices_attached[i].id) return data->devices_attached[i].dev; - if (do_rescan) - grub_device_iterate (find_device_iter, &ctx); - if (!ctx.dev_found) - { - return NULL; - } + + grub_device_iterate (find_device_iter, &ctx); + data->n_devices_attached++; if (data->n_devices_attached > data->n_devices_allocated) { @@ -617,7 +614,8 @@ find_device (struct grub_btrfs_data *data, grub_uint64_t id, int do_rescan) * sizeof (data->devices_attached[0])); if (!data->devices_attached) { - grub_device_close (ctx.dev_found); + if (ctx.dev_found) + grub_device_close (ctx.dev_found); data->devices_attached = tmp; return NULL; } @@ -894,7 +892,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, " for laddr 0x%" PRIxGRUB_UINT64_T "\n", paddr, addr); - dev = find_device (data, stripe->device_id, j); + dev = find_device (data, stripe->device_id); if (!dev) { grub_dprintf ("btrfs", @@ -971,7 +969,8 @@ grub_btrfs_unmount (struct grub_btrfs_data *data) unsigned i; /* The device 0 is closed one layer upper. */ for (i = 1; i < data->n_devices_attached; i++) - grub_device_close (data->devices_attached[i].dev); + if (data->devices_attached[i].dev) + grub_device_close (data->devices_attached[i].dev); grub_free (data->devices_attached); grub_free (data->extent); grub_free (data); -- 2.17.0