Whamcloud - gitweb
LU-4563 Fix unsafe userspace access in many proc files
[fs/lustre-release.git] / lustre / obdclass / llog_osd.c
index a47d709..fd9bfc3 100644 (file)
@@ -283,12 +283,16 @@ static int llog_osd_declare_write_rec(const struct lu_env *env,
        LASSERT(env);
        LASSERT(th);
        LASSERT(loghandle);
+       LASSERT(rec);
+       LASSERT(rec->lrh_len <= LLOG_CHUNK_SIZE);
 
        o = loghandle->lgh_obj;
        LASSERT(o);
 
+       lgi->lgi_buf.lb_len = sizeof(struct llog_log_hdr);
+       lgi->lgi_buf.lb_buf = NULL;
        /* each time we update header */
-       rc = dt_declare_record_write(env, o, sizeof(struct llog_log_hdr), 0,
+       rc = dt_declare_record_write(env, o, &lgi->lgi_buf, 0,
                                     th);
        if (rc || idx == 0) /* if error or just header */
                RETURN(rc);
@@ -307,8 +311,10 @@ static int llog_osd_declare_write_rec(const struct lu_env *env,
                lgi->lgi_off = 0;
        }
 
+       lgi->lgi_buf.lb_len = rec->lrh_len;
+       lgi->lgi_buf.lb_buf = NULL;
        /* XXX: implement declared window or multi-chunks approach */
-       rc = dt_declare_record_write(env, o, 32 * 1024, lgi->lgi_off, th);
+       rc = dt_declare_record_write(env, o, &lgi->lgi_buf, -1, th);
 
        RETURN(rc);
 }
@@ -909,9 +915,8 @@ static int llog_osd_declare_create(const struct lu_env *env,
        if (rc)
                RETURN(rc);
 
-       rc = dt_declare_record_write(env, o, LLOG_CHUNK_SIZE, 0, th);
-       if (rc)
-               RETURN(rc);
+       /* do not declare header initialization here as it's declared
+        * in llog_osd_declare_write_rec() which is always called */
 
        if (res->lgh_name) {
                struct dt_object *llog_dir;
@@ -1090,11 +1095,9 @@ static int llog_osd_setup(const struct lu_env *env, struct obd_device *obd,
                          struct obd_llog_group *olg, int ctxt_idx,
                          struct obd_device *disk_obd)
 {
-       struct local_oid_storage        *los;
        struct llog_thread_info         *lgi = llog_info(env);
        struct llog_ctxt                *ctxt;
        int                              rc = 0;
-
        ENTRY;
 
        LASSERT(obd);
@@ -1109,44 +1112,41 @@ static int llog_osd_setup(const struct lu_env *env, struct obd_device *obd,
        lgi->lgi_fid.f_oid = 1;
        lgi->lgi_fid.f_ver = 0;
        rc = local_oid_storage_init(env, disk_obd->obd_lvfs_ctxt.dt,
-                                   &lgi->lgi_fid, &los);
-       if (rc < 0)
-               return rc;
+                                   &lgi->lgi_fid,
+                                   &ctxt->loc_los_nameless);
+       if (rc != 0)
+               GOTO(out, rc);
 
        lgi->lgi_fid.f_seq = FID_SEQ_LLOG_NAME;
        lgi->lgi_fid.f_oid = 1;
        lgi->lgi_fid.f_ver = 0;
        rc = local_oid_storage_init(env, disk_obd->obd_lvfs_ctxt.dt,
-                                   &lgi->lgi_fid, &los);
+                                   &lgi->lgi_fid,
+                                   &ctxt->loc_los_named);
+       if (rc != 0) {
+               local_oid_storage_fini(env, ctxt->loc_los_nameless);
+               ctxt->loc_los_nameless = NULL;
+       }
+
+       GOTO(out, rc);
+
+out:
        llog_ctxt_put(ctxt);
        return rc;
 }
 
 static int llog_osd_cleanup(const struct lu_env *env, struct llog_ctxt *ctxt)
 {
-       struct dt_device                *dt;
-       struct ls_device                *ls;
-       struct local_oid_storage        *los, *nlos;
-
-       LASSERT(ctxt->loc_exp->exp_obd);
-       dt = ctxt->loc_exp->exp_obd->obd_lvfs_ctxt.dt;
-       ls = ls_device_get(dt);
-       if (IS_ERR(ls))
-               RETURN(PTR_ERR(ls));
-
-       mutex_lock(&ls->ls_los_mutex);
-       los = dt_los_find(ls, FID_SEQ_LLOG);
-       nlos = dt_los_find(ls, FID_SEQ_LLOG_NAME);
-       mutex_unlock(&ls->ls_los_mutex);
-       if (los != NULL) {
-               dt_los_put(los);
-               local_oid_storage_fini(env, los);
+       if (ctxt->loc_los_nameless != NULL) {
+               local_oid_storage_fini(env, ctxt->loc_los_nameless);
+               ctxt->loc_los_nameless = NULL;
        }
-       if (nlos != NULL) {
-               dt_los_put(nlos);
-               local_oid_storage_fini(env, nlos);
+
+       if (ctxt->loc_los_named != NULL) {
+               local_oid_storage_fini(env, ctxt->loc_los_named);
+               ctxt->loc_los_named = NULL;
        }
-       ls_device_put(env, ls);
+
        return 0;
 }
 
@@ -1302,7 +1302,9 @@ int llog_osd_put_cat_list(const struct lu_env *env, struct dt_device *d,
        if (IS_ERR(th))
                GOTO(out, rc = PTR_ERR(th));
 
-       rc = dt_declare_record_write(env, o, size, lgi->lgi_off, th);
+       lgi->lgi_buf.lb_len = size;
+       lgi->lgi_buf.lb_buf = idarray;
+       rc = dt_declare_record_write(env, o, &lgi->lgi_buf, lgi->lgi_off, th);
        if (rc)
                GOTO(out, rc);
 
@@ -1310,8 +1312,6 @@ int llog_osd_put_cat_list(const struct lu_env *env, struct dt_device *d,
        if (rc)
                GOTO(out_trans, rc);
 
-       lgi->lgi_buf.lb_buf = idarray;
-       lgi->lgi_buf.lb_len = size;
        rc = dt_record_write(env, o, &lgi->lgi_buf, &lgi->lgi_off, th);
        if (rc)
                CDEBUG(D_INODE, "error writeing CATALOGS: rc = %d\n", rc);