Whamcloud - gitweb
LU-4019 ofd: setattr don't udpate lvbo with object referenced
[fs/lustre-release.git] / lustre / ofd / ofd_obd.c
index 429023b..8bcbd06 100644 (file)
@@ -58,6 +58,8 @@ static int ofd_export_stats_init(struct ofd_device *ofd,
 
        ENTRY;
 
+       LASSERT(obd->obd_uses_nid_stats);
+
        if (obd_uuid_equals(&exp->exp_client_uuid, &obd->obd_uuid))
                /* Self-export gets no proc entry */
                RETURN(0);
@@ -77,9 +79,7 @@ static int ofd_export_stats_init(struct ofd_device *ofd,
        stats = exp->exp_nid_stats;
        LASSERT(stats != NULL);
 
-       num_stats = (sizeof(*obd->obd_type->typ_dt_ops) / sizeof(void *)) +
-                    LPROC_OFD_LAST - 1;
-
+       num_stats = NUM_OBD_STATS + LPROC_OFD_LAST;
        stats->nid_stats = lprocfs_alloc_stats(num_stats,
                                               LPROCFS_STATS_FLAG_NOPERCPU);
        if (stats->nid_stats == NULL)
@@ -137,7 +137,6 @@ static int ofd_parse_connect_data(const struct lu_env *env,
        fed->fed_group = data->ocd_group;
 
        data->ocd_connect_flags &= OST_CONNECT_SUPPORTED;
-       exp->exp_connect_data = *data;
        data->ocd_version = LUSTRE_VERSION_CODE;
 
        /* Kindly make sure the SKIP_ORPHAN flag is from MDS. */
@@ -156,7 +155,7 @@ static int ofd_parse_connect_data(const struct lu_env *env,
                data->ocd_grant_extent = ofd->ofd_dt_conf.ddp_grant_frag >> 10;
        }
 
-       if (exp_connect_flags(exp) & OBD_CONNECT_GRANT)
+       if (data->ocd_connect_flags & OBD_CONNECT_GRANT)
                data->ocd_grant = ofd_grant_connect(env, exp, data->ocd_grant,
                                                    new_connection);
 
@@ -316,7 +315,7 @@ static int ofd_obd_connect(const struct lu_env *env, struct obd_export **_exp,
        }
 
        CDEBUG(D_HA, "%s: get connection from MDS %d\n", obd->obd_name,
-              data->ocd_group);
+              data ? data->ocd_group : -1);
 
 out:
        if (rc != 0) {
@@ -888,18 +887,6 @@ int ofd_setattr(const struct lu_env *env, struct obd_export *exp,
        if (rc)
                GOTO(out_unlock, rc);
 
-       res = ldlm_resource_get(ns, NULL, &info->fti_resid, LDLM_EXTENT, 0);
-       if (res != NULL) {
-               ldlm_res_lvbo_update(res, NULL, 0);
-               ldlm_resource_putref(res);
-       }
-
-       oinfo->oi_oa->o_valid = OBD_MD_FLID;
-
-       /* Quota release needs uid/gid info */
-       rc = ofd_attr_get(env, fo, &info->fti_attr);
-       obdo_from_la(oinfo->oi_oa, &info->fti_attr,
-                    OFD_VALID_FLAGS | LA_UID | LA_GID);
        ofd_info2oti(info, oti);
 
        ofd_counter_incr(exp, LPROC_OFD_STATS_SETATTR, oti->oti_jobid, 1);
@@ -907,6 +894,19 @@ int ofd_setattr(const struct lu_env *env, struct obd_export *exp,
 out_unlock:
        ofd_object_put(env, fo);
 out:
+       if (rc == 0) {
+               /* we do not call this before to avoid lu_object_find() in
+                *  ->lvbo_update() holding another reference on the object.
+                * otherwise concurrent destroy can make the object unavailable
+                * for 2nd lu_object_find() waiting for the first reference
+                * to go... deadlock! */
+               res = ldlm_resource_get(ns, NULL, &info->fti_resid, LDLM_EXTENT, 0);
+               if (res != NULL) {
+                       ldlm_res_lvbo_update(res, NULL, 0);
+                       ldlm_resource_putref(res);
+               }
+       }
+
        return rc;
 }
 
@@ -1305,6 +1305,22 @@ int ofd_create(const struct lu_env *env, struct obd_export *exp,
                        }
                }
 
+               /* This can happen if a new OST is formatted and installed
+                * in place of an old one at the same index.  Instead of
+                * precreating potentially millions of deleted old objects
+                * (possibly filling the OST), only precreate the last batch.
+                * LFSCK will eventually clean up any orphans. LU-14 */
+               if (diff > 5 * OST_MAX_PRECREATE) {
+                       diff = OST_MAX_PRECREATE / 2;
+                       LCONSOLE_WARN("%s: precreate FID "DOSTID" is over %u "
+                                     "larger than the LAST_ID "DOSTID", only "
+                                     "precreating the last %u objects.\n",
+                                     ofd_name(ofd), POSTID(&oa->o_oi),
+                                     5 * OST_MAX_PRECREATE,
+                                     POSTID(&oseq->os_oi), diff);
+                       ofd_seq_last_oid_set(oseq, ostid_id(&oa->o_oi) - diff);
+               }
+
                while (diff > 0) {
                        next_id = ofd_seq_last_oid(oseq) + 1;
                        count = ofd_precreate_batch(ofd, diff);
@@ -1367,7 +1383,6 @@ int ofd_getattr(const struct lu_env *env, struct obd_export *exp,
        struct ofd_device       *ofd = ofd_exp(exp);
        struct ofd_thread_info  *info;
        struct ofd_object       *fo;
-       __u64                    curr_version;
        int                      rc = 0;
 
        ENTRY;
@@ -1385,19 +1400,27 @@ int ofd_getattr(const struct lu_env *env, struct obd_export *exp,
        fo = ofd_object_find(env, ofd, &info->fti_fid);
        if (IS_ERR(fo))
                GOTO(out, rc = PTR_ERR(fo));
+       if (!ofd_object_exists(fo))
+               GOTO(out_put, rc = -ENOENT);
+
        LASSERT(fo != NULL);
        rc = ofd_attr_get(env, fo, &info->fti_attr);
        oinfo->oi_oa->o_valid = OBD_MD_FLID;
-       if (rc == 0)
+       if (rc == 0) {
+               __u64 curr_version;
+
                obdo_from_la(oinfo->oi_oa, &info->fti_attr,
                             OFD_VALID_FLAGS | LA_UID | LA_GID);
 
-       /* Store object version in reply */
-       curr_version = dt_version_get(env, ofd_object_child(fo));
-       if ((__s64)curr_version != -EOPNOTSUPP) {
-               oinfo->oi_oa->o_valid |= OBD_MD_FLDATAVERSION;
-               oinfo->oi_oa->o_data_version = curr_version;
+               /* Store object version in reply */
+               curr_version = dt_version_get(env, ofd_object_child(fo));
+               if ((__s64)curr_version != -EOPNOTSUPP) {
+                       oinfo->oi_oa->o_valid |= OBD_MD_FLDATAVERSION;
+                       oinfo->oi_oa->o_data_version = curr_version;
+               }
        }
+
+out_put:
        ofd_object_put(env, fo);
 out:
        RETURN(rc);