Re: [1/4] DST: Distributed storage documentation.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Dec 10, 2007 at 08:56:49PM +0100, Kay Sievers ([email protected]) wrote:
> On Mon, 2007-12-10 at 22:51 +0300, Evgeniy Polyakov wrote:
> > On Mon, Dec 10, 2007 at 08:44:55PM +0100, Kay Sievers ([email protected]) wrote:
> > > > > > Actually not - I have to set reference counter to something other than 1
> > > > > > or +/- 1, and thus will have to call kref_get() in a loop, which is a
> > > > > > very ugly step. Is there kref_set() or somethinglike that? At least not
> > > > > > in 2.6.22 what I'm using for now.
> > > > > 
> > > > > Yeah, a loop would look pretty ugly. How about just adding kref_set(),
> > > > > if you need it.
> > > > 
> > > > Well, then it distributed storage will not be able to build as
> > > > standalone module, and kref_set() itself will not be accepted as a single 
> > > > patch, since there are no in-kernel users :)
> > > > It is easily doable though.
> > > 
> > > Most rules have exceptions. :) Send a patch, so we can see how it looks
> > > like.
> > 
> > It looks really non-trivial :)
> 
> Yeah, it does. :)
> We miss an EXPORT_SYMBOL(), right?

Yep :)

diff --git a/include/linux/kref.h b/include/linux/kref.h
index 6fee353..5d18563 100644
--- a/include/linux/kref.h
+++ b/include/linux/kref.h
@@ -24,6 +24,7 @@ struct kref {
 	atomic_t refcount;
 };
 
+void kref_set(struct kref *kref, int num);
 void kref_init(struct kref *kref);
 void kref_get(struct kref *kref);
 int kref_put(struct kref *kref, void (*release) (struct kref *kref));
diff --git a/lib/kref.c b/lib/kref.c
index a6dc3ec..9ecd6e8 100644
--- a/lib/kref.c
+++ b/lib/kref.c
@@ -15,13 +15,23 @@
 #include <linux/module.h>
 
 /**
+ * kref_set - initialize object and set refcount to requested number.
+ * @kref: object in question.
+ * @num: initial reference counter
+ */
+void kref_set(struct kref *kref, int num)
+{
+	atomic_set(&kref->refcount, num);
+	smp_mb();
+}
+
+/**
  * kref_init - initialize object.
  * @kref: object in question.
  */
 void kref_init(struct kref *kref)
 {
-	atomic_set(&kref->refcount,1);
-	smp_mb();
+	kref_set(kref, 1);
 }
 
 /**
@@ -61,6 +71,7 @@ int kref_put(struct kref *kref, void (*release)(struct kref *kref))
 	return 0;
 }
 
+EXPORT_SYMBOL(kref_set);
 EXPORT_SYMBOL(kref_init);
 EXPORT_SYMBOL(kref_get);
 EXPORT_SYMBOL(kref_put);

-- 
	Evgeniy Polyakov
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux