From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1LyeLP-0000jR-Sd for mharc-grub-devel@gnu.org; Mon, 27 Apr 2009 23:50:55 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LyeLN-0000hl-OX for grub-devel@gnu.org; Mon, 27 Apr 2009 23:50:53 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LyeLJ-0000ca-8B for grub-devel@gnu.org; Mon, 27 Apr 2009 23:50:53 -0400 Received: from [199.232.76.173] (port=57125 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LyeLJ-0000cJ-2B for grub-devel@gnu.org; Mon, 27 Apr 2009 23:50:49 -0400 Received: from c60.cesmail.net ([216.154.195.49]:17615) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.60) (envelope-from ) id 1LyeLI-0004cg-Io for grub-devel@gnu.org; Mon, 27 Apr 2009 23:50:48 -0400 Received: from unknown (HELO smtprelay2.cesmail.net) ([192.168.1.112]) by c60.cesmail.net with ESMTP; 27 Apr 2009 23:50:47 -0400 Received: from [192.168.0.22] (static-72-92-88-10.phlapa.fios.verizon.net [72.92.88.10]) by smtprelay2.cesmail.net (Postfix) with ESMTPSA id 9584B34C6A for ; Mon, 27 Apr 2009 23:48:37 -0400 (EDT) From: Pavel Roskin To: The development of GRUB 2 In-Reply-To: <20090427.184533.105744402.davem@davemloft.net> References: <20090426.225757.05232059.davem@davemloft.net> <1240871171.11406.106.camel@mj> <1240882672.29799.10.camel@mj> <20090427.184533.105744402.davem@davemloft.net> Content-Type: text/plain Date: Mon, 27 Apr 2009 23:50:45 -0400 Message-Id: <1240890645.29799.99.camel@mj> Mime-Version: 1.0 X-Mailer: Evolution 2.26.1 (2.26.1-2.fc11) Content-Transfer-Encoding: 7bit X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: Re: [PATCH] Re: Revision 2136 breaks two-disk configuarion X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Apr 2009 03:50:53 -0000 On Mon, 2009-04-27 at 18:45 -0700, David Miller wrote: > Thanks for fixing this Pavel. I suspect this bug is why the close was > left as a NOP function all of this time. Maybe. > Please commit this as it seems you haven't already :-) I was about to commit it when I realized that the same could be done using a reference counter in struct grub_partition. It may be an overkill for this purpose, but maybe there will be more users of the partition table in the future. Besides, this patch could set an example. Please have a cursory look to make sure it's a good example. ChangeLog: * grub/partition.h (struct grub_partition): Add refcount. (grub_partition_ref): New inline function. (grub_partition_unref): Likewise. * kern/disk.c (grub_disk_close): Use grub_partition_unref(). * disk/fs_uuid.c (grub_fs_uuid_open): Use grub_partition_ref(). diff --git a/disk/fs_uuid.c b/disk/fs_uuid.c index 9d83bb8..12086b2 100644 --- a/disk/fs_uuid.c +++ b/disk/fs_uuid.c @@ -25,6 +25,7 @@ #include #include +#include static grub_device_t search_fs_uuid (const char *key, unsigned long *count) @@ -88,7 +89,7 @@ grub_fs_uuid_open (const char *name, grub_disk_t disk) disk->total_sectors = dev->disk->total_sectors; disk->has_partitions = 0; - disk->partition = dev->disk->partition; + disk->partition = grub_partition_ref (dev->disk->partition); disk->data = dev->disk; return GRUB_ERR_NONE; diff --git a/include/grub/partition.h b/include/grub/partition.h index 6e74cd5..c3e4d15 100644 --- a/include/grub/partition.h +++ b/include/grub/partition.h @@ -62,6 +62,9 @@ struct grub_partition /* The index of this partition in the partition table. */ int index; + + /* Reference count. */ + int refcount; /* Partition map type specific data. */ void *data; @@ -110,4 +113,23 @@ grub_partition_get_len (const grub_partition_t p) return p->len; } +/* Return a copy by reference of the original partition. */ +static inline grub_partition_t +grub_partition_ref (grub_partition_t p) +{ + if (p) + p->refcount++; + return p; +} + +/* Return partition to be freed if it can be freed. */ +static inline grub_partition_t +grub_partition_unref (const grub_partition_t p) +{ + if (p && p->refcount-- <= 0) + return p; + else + return 0; +} + #endif /* ! GRUB_PART_HEADER */ diff --git a/kern/disk.c b/kern/disk.c index 8a92989..070cab3 100644 --- a/kern/disk.c +++ b/kern/disk.c @@ -324,7 +324,7 @@ grub_disk_close (grub_disk_t disk) /* Reset the timer. */ grub_last_time = grub_get_time_ms (); - grub_free (disk->partition); + grub_free (grub_partition_unref (disk->partition)); grub_free ((void *) disk->name); grub_free (disk); } -- Regards, Pavel Roskin