Whamcloud - gitweb
lu: add ->loo_object_start() method called late during object allocation. It can...
authornikita <nikita>
Wed, 16 Aug 2006 15:40:56 +0000 (15:40 +0000)
committernikita <nikita>
Wed, 16 Aug 2006 15:40:56 +0000 (15:40 +0000)
lustre/include/lu_object.h
lustre/obdclass/lu_object.c

index 447738a..3c1103b 100644 (file)
@@ -169,6 +169,13 @@ struct lu_object_operations {
         int (*loo_object_init)(const struct lu_context *ctx,
                                struct lu_object *o);
         /*
+         * Called (in top-to-bottom order) during object allocation after all
+         * layers were allocated and initialized. Can be used to perform
+         * initialization depending on lower layers.
+         */
+        int (*loo_object_start)(const struct lu_context *ctx,
+                                struct lu_object *o);
+        /*
          * Called before ->loo_object_free() to signal that object is being
          * destroyed. Dual to ->loo_object_init().
          */
index fa60c02..862fe2b 100644 (file)
@@ -111,6 +111,7 @@ static struct lu_object *lu_object_alloc(const struct lu_context *ctxt,
 {
         struct lu_object *scan;
         struct lu_object *top;
+        struct list_head *layers;
         int clean;
         int result;
 
@@ -128,14 +129,14 @@ static struct lu_object *lu_object_alloc(const struct lu_context *ctxt,
          * after this point.
          */
         top->lo_header->loh_fid = *f;
+        layers = &top->lo_header->loh_layers;
         do {
                 /*
                  * Call ->loo_object_init() repeatedly, until no more new
                  * object slices are created.
                  */
                 clean = 1;
-                list_for_each_entry(scan,
-                                    &top->lo_header->loh_layers, lo_linkage) {
+                list_for_each_entry(scan, layers, lo_linkage) {
                         if (scan->lo_flags & LU_OBJECT_ALLOCATED)
                                 continue;
                         clean = 0;
@@ -148,6 +149,17 @@ static struct lu_object *lu_object_alloc(const struct lu_context *ctxt,
                         scan->lo_flags |= LU_OBJECT_ALLOCATED;
                 }
         } while (!clean);
+
+        list_for_each_entry_reverse(scan, layers, lo_linkage) {
+                if (scan->lo_ops->loo_object_start != NULL) {
+                        result = scan->lo_ops->loo_object_start(ctxt, scan);
+                        if (result != 0) {
+                                lu_object_free(ctxt, top);
+                                RETURN(ERR_PTR(result));
+                        }
+                }
+        }
+
         s->ls_stats.s_created ++;
         RETURN(top);
 }