Whamcloud - gitweb
LU-6838 llog: limit file size of plain logs
[fs/lustre-release.git] / lustre / obdclass / llog_cat.c
index 1e0c1fd..86a2047 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -175,6 +171,25 @@ static int llog_cat_new_log(const struct lu_env *env,
               POSTID(&cathandle->lgh_id.lgl_oi));
 
        loghandle->lgh_hdr->llh_cat_idx = rec->lid_hdr.lrh_index;
+
+       /* limit max size of plain llog so that space can be
+        * released sooner, especially on small filesystems */
+       /* 2MB for the cases when free space hasn't been learned yet */
+       loghandle->lgh_max_size = 2 << 20;
+       dt = lu2dt_dev(cathandle->lgh_obj->do_lu.lo_dev);
+       rc = dt_statfs(env, dt, &lgi->lgi_statfs);
+       if (rc == 0 && lgi->lgi_statfs.os_bfree > 0) {
+               __u64 freespace = (lgi->lgi_statfs.os_bfree *
+                                 lgi->lgi_statfs.os_bsize) >> 6;
+               if (freespace < loghandle->lgh_max_size)
+                       loghandle->lgh_max_size = freespace;
+               /* shouldn't be > 128MB in any case?
+                * it's 256K records of 512 bytes each */
+               if (freespace > (128 << 20))
+                       loghandle->lgh_max_size = 128 << 20;
+       }
+       rc = 0;
+
 out:
        if (handle != NULL) {
                handle->th_result = rc >= 0 ? 0 : rc;
@@ -911,7 +926,7 @@ static int llog_cat_size_cb(const struct lu_env *env,
        size = llog_size(env, llh);
        *cum_size += size;
 
-       CDEBUG(D_INFO, "Add llog entry "DOSTID" size "LPU64"\n",
+       CDEBUG(D_INFO, "Add llog entry "DOSTID" size %llu\n",
               POSTID(&llh->lgh_id.lgl_oi), size);
 
        llog_handle_put(llh);