From: Pavel Roskin <proski@gnu.org>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCH] Re: Revision 2136 breaks two-disk configuarion
Date: Mon, 27 Apr 2009 23:50:45 -0400 [thread overview]
Message-ID: <1240890645.29799.99.camel@mj> (raw)
In-Reply-To: <20090427.184533.105744402.davem@davemloft.net>
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 <grub/types.h>
#include <grub/fs.h>
+#include <grub/partition.h>
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
next prev parent reply other threads:[~2009-04-28 3:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-27 5:25 Revision 2136 breaks two-disk configuarion Pavel Roskin
2009-04-27 5:57 ` David Miller
2009-04-27 22:26 ` Pavel Roskin
2009-04-28 1:37 ` [PATCH] " Pavel Roskin
2009-04-28 1:45 ` David Miller
2009-04-28 3:50 ` Pavel Roskin [this message]
2009-04-28 8:59 ` David Miller
2009-04-28 13:26 ` Pavel Roskin
2009-04-28 8:59 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1240890645.29799.99.camel@mj \
--to=proski@gnu.org \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.