Whamcloud - gitweb
Prevent false "leak" because of OBD memory accounting.
[fs/lustre-release.git] / lustre / lov / lov_obd.c
index 04f5481..9c54c6a 100644 (file)
@@ -219,9 +219,10 @@ static int lov_create(struct lustre_handle *conn, struct obdo *oa,
         ENTRY;
 
         if (!ea) {
-                CERROR("lov_create needs EA for striping information\n");
+                CERROR("lov_create needs ea\n");
                 RETURN(-EINVAL);
         }
+
         if (!export)
                 RETURN(-EINVAL);
 
@@ -315,6 +316,12 @@ static int lov_destroy(struct lustre_handle *conn, struct obdo *oa,
                 RETURN(-EINVAL);
         }
 
+        if (lsm->lsm_magic != LOV_MAGIC) {
+                CERROR("LOV striping magic bad %#lx != %#lx\n",
+                       lsm->lsm_magic, LOV_MAGIC);
+                RETURN(-EINVAL);
+        }
+
         if (!export || !export->exp_obd)
                 RETURN(-ENODEV);
 
@@ -348,6 +355,12 @@ static int lov_getattr(struct lustre_handle *conn, struct obdo *oa,
                 RETURN(-EINVAL);
         }
 
+        if (lsm->lsm_magic != LOV_MAGIC) {
+                CERROR("LOV striping magic bad %#lx != %#lx\n",
+                       lsm->lsm_magic, LOV_MAGIC);
+                RETURN(-EINVAL);
+        }
+
         if (!export || !export->exp_obd)
                 RETURN(-ENODEV);
 
@@ -408,10 +421,16 @@ static int lov_setattr(struct lustre_handle *conn, struct obdo *oa,
                 RETURN(-EINVAL);
         }
 
+        if (lsm->lsm_magic != LOV_MAGIC) {
+                CERROR("LOV striping magic bad %#lx != %#lx\n",
+                       lsm->lsm_magic, LOV_MAGIC);
+                RETURN(-EINVAL);
+        }
+
         if (!export || !export->exp_obd)
                 RETURN(-ENODEV);
 
-        if (oa->o_valid && OBD_MD_FLSIZE)
+        if (oa->o_valid & OBD_MD_FLSIZE)
                 CERROR("setting size on an LOV object is totally broken\n");
 
         lov = &export->exp_obd->u.lov;
@@ -449,6 +468,12 @@ static int lov_open(struct lustre_handle *conn, struct obdo *oa,
                 RETURN(-EINVAL);
         }
 
+        if (lsm->lsm_magic != LOV_MAGIC) {
+                CERROR("LOV striping magic bad %#lx != %#lx\n",
+                       lsm->lsm_magic, LOV_MAGIC);
+                RETURN(-EINVAL);
+        }
+
         if (!export || !export->exp_obd)
                 RETURN(-ENODEV);
 
@@ -495,6 +520,12 @@ static int lov_close(struct lustre_handle *conn, struct obdo *oa,
                 RETURN(-EINVAL);
         }
 
+        if (lsm->lsm_magic != LOV_MAGIC) {
+                CERROR("LOV striping magic bad %#lx != %#lx\n",
+                       lsm->lsm_magic, LOV_MAGIC);
+                RETURN(-EINVAL);
+        }
+
         if (!export || !export->exp_obd)
                 RETURN(-ENODEV);
 
@@ -542,7 +573,7 @@ static __u64 lov_offset(struct lov_stripe_md *lsm, __u64 lov_off, int stripeno)
         else
                 stripe_off -= stripeno * ssize;
 
-        return lov_off + stripe_off;
+        return lov_off * ssize + stripe_off;
 }
 
 /* compute which stripe offset "lov_off" will be written into */
@@ -573,7 +604,13 @@ static int lov_punch(struct lustre_handle *conn, struct obdo *oa,
         ENTRY;
 
         if (!lsm) {
-                CERROR("LOV requires striping ea for desctruction\n");
+                CERROR("LOV requires striping ea\n");
+                RETURN(-EINVAL);
+        }
+
+        if (lsm->lsm_magic != LOV_MAGIC) {
+                CERROR("LOV striping magic bad %#lx != %#lx\n",
+                       lsm->lsm_magic, LOV_MAGIC);
                 RETURN(-EINVAL);
         }
 
@@ -647,6 +684,17 @@ static inline int lov_brw(int cmd, struct lustre_handle *conn,
         int *where;
         ENTRY;
 
+        if (!lsm) {
+                CERROR("LOV requires striping ea\n");
+                RETURN(-EINVAL);
+        }
+
+        if (lsm->lsm_magic != LOV_MAGIC) {
+                CERROR("LOV striping magic bad %#lx != %#lx\n",
+                       lsm->lsm_magic, LOV_MAGIC);
+                RETURN(-EINVAL);
+        }
+
         lov = &export->exp_obd->u.lov;
 
         our_cb = ll_init_cb();
@@ -677,9 +725,8 @@ static inline int lov_brw(int cmd, struct lustre_handle *conn,
                         atomic_inc(&our_cb->refcount);
         }
 
-        for (i = 0, loi = lsm->lsm_oinfo, si = si_last = stripeinfo;
-             i < stripe_count;
-             i++, loi++, si_last = si, si++) {
+        for (i = 0, loi = lsm->lsm_oinfo, si_last = si = stripeinfo;
+             i < stripe_count; i++, loi++, si_last = si, si++) {
                 if (i > 0)
                         si->index = si_last->index + si_last->bufct;
                 si->lsm.lsm_object_id = loi->loi_id;
@@ -697,7 +744,7 @@ static inline int lov_brw(int cmd, struct lustre_handle *conn,
                 stripeinfo[which].subcount++;
         }
 
-        for (i = 0, si = stripeinfo; i < stripe_count; i++) {
+        for (i = 0, si = stripeinfo; i < stripe_count; i++, si++) {
                 int shift = si->index;
 
                 if (si->bufct) {
@@ -733,7 +780,13 @@ static int lov_enqueue(struct lustre_handle *conn, struct lov_stripe_md *lsm,
         ENTRY;
 
         if (!lsm) {
-                CERROR("LOV requires striping ea for desctruction\n");
+                CERROR("LOV requires striping ea\n");
+                RETURN(-EINVAL);
+        }
+
+        if (lsm->lsm_magic != LOV_MAGIC) {
+                CERROR("LOV striping magic bad %#lx != %#lx\n",
+                       lsm->lsm_magic, LOV_MAGIC);
                 RETURN(-EINVAL);
         }
 
@@ -780,7 +833,13 @@ static int lov_cancel(struct lustre_handle *conn, struct lov_stripe_md *lsm,
         ENTRY;
 
         if (!lsm) {
-                CERROR("LOV requires striping ea for lock cancellation\n");
+                CERROR("LOV requires striping ea\n");
+                RETURN(-EINVAL);
+        }
+
+        if (lsm->lsm_magic != LOV_MAGIC) {
+                CERROR("LOV striping magic bad %#lx != %#lx\n",
+                       lsm->lsm_magic, LOV_MAGIC);
                 RETURN(-EINVAL);
         }
 
@@ -807,6 +866,40 @@ static int lov_cancel(struct lustre_handle *conn, struct lov_stripe_md *lsm,
         RETURN(rc);
 }
 
+static int lov_cancel_unused(struct lustre_handle *conn,
+                             struct lov_stripe_md *lsm)
+{
+        struct obd_export *export = class_conn2export(conn);
+        struct lov_obd *lov;
+        struct lov_oinfo *loi;
+        int rc = 0, i;
+        ENTRY;
+
+        if (!lsm) {
+                CERROR("LOV requires striping ea for lock cancellation\n");
+                RETURN(-EINVAL);
+        }
+
+        if (!export || !export->exp_obd)
+                RETURN(-ENODEV);
+
+        lov = &export->exp_obd->u.lov;
+        for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
+                struct lov_stripe_md submd;
+
+                submd.lsm_object_id = loi->loi_id;
+                submd.lsm_mds_easize = lov_mds_md_size(lsm->lsm_ost_count);
+                submd.lsm_stripe_count = 0;
+                rc = obd_cancel_unused(&lov->tgts[loi->loi_ost_idx].conn,
+                                       &submd);
+                if (rc)
+                        CERROR("Error cancel unused objid "LPX64" subobj "LPX64
+                               " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
+                               loi->loi_id, loi->loi_ost_idx, rc);
+        }
+        RETURN(rc);
+}
+
 static int lov_statfs(struct lustre_handle *conn, struct obd_statfs *osfs)
 {
         struct obd_export *export = class_conn2export(conn);
@@ -870,7 +963,8 @@ struct obd_ops lov_obd_ops = {
         o_brw:         lov_brw,
         o_punch:       lov_punch,
         o_enqueue:     lov_enqueue,
-        o_cancel:      lov_cancel
+        o_cancel:      lov_cancel,
+        o_cancel_unused: lov_cancel_unused
 };