Whamcloud - gitweb
LU-2139 osc: Track and limit "unstable" pages
[fs/lustre-release.git] / lustre / lov / lov_obd.c
index 81c01f2..0eb30ec 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -61,7 +61,7 @@
 #include <lprocfs_status.h>
 #include <lustre_param.h>
 #include <cl_object.h>
-#include <lclient.h> /* for cl_client_lru */
+#include <lclient.h>
 #include <lustre/ll_fiemap.h>
 #include <lustre_log.h>
 #include <lustre_fid.h>
@@ -747,9 +747,11 @@ static void __lov_del_obd(struct obd_device *obd, struct lov_tgt_desc *tgt)
 
 void lov_fix_desc_stripe_size(__u64 *val)
 {
-       if (*val < LOV_DEFAULT_STRIPE_SIZE) {
-               LCONSOLE_WARN("Increasing default stripe size to min %u\n",
-                             LOV_DEFAULT_STRIPE_SIZE);
+       if (*val < LOV_MIN_STRIPE_SIZE) {
+               if (*val != 0)
+                       LCONSOLE_INFO("Increasing default stripe size to "
+                                     "minimum %u\n",
+                                     LOV_DEFAULT_STRIPE_SIZE);
                *val = LOV_DEFAULT_STRIPE_SIZE;
        } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
                *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
@@ -1956,9 +1958,9 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                         RETURN(-EINVAL);
 
                 /* copy UUID */
-                if (cfs_copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd),
-                                     min((int) data->ioc_plen2,
-                                         (int) sizeof(struct obd_uuid))))
+               if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(osc_obd),
+                                min((int)data->ioc_plen2,
+                                    (int)sizeof(struct obd_uuid))))
                         RETURN(-EFAULT);
 
                flags = uarg ? *(__u32*)uarg : 0;
@@ -1968,7 +1970,7 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                                 flags);
                 if (rc)
                         RETURN(rc);
-                if (cfs_copy_to_user(data->ioc_pbuf1, &stat_buf,
+               if (copy_to_user(data->ioc_pbuf1, &stat_buf,
                                      min((int) data->ioc_plen1,
                                          (int) sizeof(stat_buf))))
                         RETURN(-EFAULT);
@@ -2014,7 +2016,7 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                         *genp = lov->lov_tgts[i]->ltd_gen;
                 }
 
-                if (cfs_copy_to_user((void *)uarg, buf, len))
+               if (copy_to_user((void *)uarg, buf, len))
                         rc = -EFAULT;
                 obd_ioctl_freedata(buf, len);
                 break;
@@ -2033,13 +2035,13 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                 struct lov_tgt_desc *tgt = NULL;
                 struct obd_quotactl *oqctl;
 
-                if (qctl->qc_valid == QC_OSTIDX) {
-                        if (qctl->qc_idx < 0 || count <= qctl->qc_idx)
-                                RETURN(-EINVAL);
+               if (qctl->qc_valid == QC_OSTIDX) {
+                       if (count <= qctl->qc_idx)
+                               RETURN(-EINVAL);
 
-                        tgt = lov->lov_tgts[qctl->qc_idx];
-                        if (!tgt || !tgt->ltd_exp)
-                                RETURN(-EINVAL);
+                       tgt = lov->lov_tgts[qctl->qc_idx];
+                       if (!tgt || !tgt->ltd_exp)
+                               RETURN(-EINVAL);
                 } else if (qctl->qc_valid == QC_UUID) {
                         for (i = 0; i < count; i++) {
                                 tgt = lov->lov_tgts[i];
@@ -2274,8 +2276,29 @@ static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
         int cur_stripe = 0, cur_stripe_wrap = 0, stripe_count;
         unsigned int buffer_size = FIEMAP_BUFFER_SIZE;
 
-        if (lsm == NULL)
-                GOTO(out, rc = 0);
+       if (!lsm_has_objects(lsm)) {
+               if (lsm && lsm_is_released(lsm) && (fm_key->fiemap.fm_start <
+                   fm_key->oa.o_size)) {
+                       /* released file, return a minimal FIEMAP if
+                        * request fits in file-size.
+                        */
+                       fiemap->fm_mapped_extents = 1;
+                       fiemap->fm_extents[0].fe_logical =
+                                               fm_key->fiemap.fm_start;
+                       if (fm_key->fiemap.fm_start + fm_key->fiemap.fm_length <
+                           fm_key->oa.o_size)
+                               fiemap->fm_extents[0].fe_length =
+                                               fm_key->fiemap.fm_length;
+                       else
+                               fiemap->fm_extents[0].fe_length =
+                                               fm_key->oa.o_size -
+                                               fm_key->fiemap.fm_start;
+                       fiemap->fm_extents[0].fe_flags |=
+                                               (FIEMAP_EXTENT_UNKNOWN |
+                                                FIEMAP_EXTENT_LAST);
+               }
+               GOTO(out, rc = 0);
+       }
 
         if (fiemap_count_to_size(fm_key->fiemap.fm_extent_count) < buffer_size)
                 buffer_size = fiemap_count_to_size(fm_key->fiemap.fm_extent_count);
@@ -2473,7 +2496,8 @@ skip_last_device_calc:
         fiemap->fm_mapped_extents = current_extent;
 
 out:
-        OBD_FREE_LARGE(fm_local, buffer_size);
+       if (fm_local)
+               OBD_FREE_LARGE(fm_local, buffer_size);
         return rc;
 }
 
@@ -2711,16 +2735,16 @@ static int lov_extent_calc(struct obd_export *exp, struct lov_stripe_md *lsm,
 
 void lov_stripe_lock(struct lov_stripe_md *md)
 {
-       LASSERT(md->lsm_lock_owner != cfs_curproc_pid());
+       LASSERT(md->lsm_lock_owner != current_pid());
        spin_lock(&md->lsm_lock);
        LASSERT(md->lsm_lock_owner == 0);
-       md->lsm_lock_owner = cfs_curproc_pid();
+       md->lsm_lock_owner = current_pid();
 }
 EXPORT_SYMBOL(lov_stripe_lock);
 
 void lov_stripe_unlock(struct lov_stripe_md *md)
 {
-       LASSERT(md->lsm_lock_owner == cfs_curproc_pid());
+       LASSERT(md->lsm_lock_owner == current_pid());
        md->lsm_lock_owner = 0;
        spin_unlock(&md->lsm_lock);
 }
@@ -2877,14 +2901,14 @@ struct obd_ops lov_obd_ops = {
         .o_quotacheck          = lov_quotacheck,
 };
 
-cfs_mem_cache_t *lov_oinfo_slab;
+struct kmem_cache *lov_oinfo_slab;
 
 extern struct lu_kmem_descr lov_caches[];
 
 int __init lov_init(void)
 {
         struct lprocfs_static_vars lvars = { 0 };
-        int rc, rc2;
+       int rc;
         ENTRY;
 
         /* print an address of _any_ initialized kernel symbol from this
@@ -2896,9 +2920,9 @@ int __init lov_init(void)
         if (rc)
                 return rc;
 
-        lov_oinfo_slab = cfs_mem_cache_create("lov_oinfo",
-                                              sizeof(struct lov_oinfo),
-                                              0, CFS_SLAB_HWCACHE_ALIGN);
+       lov_oinfo_slab = kmem_cache_create("lov_oinfo",
+                                          sizeof(struct lov_oinfo), 0,
+                                          SLAB_HWCACHE_ALIGN, NULL);
         if (lov_oinfo_slab == NULL) {
                 lu_kmem_fini(lov_caches);
                 return -ENOMEM;
@@ -2909,8 +2933,7 @@ int __init lov_init(void)
                                  LUSTRE_LOV_NAME, &lov_device_type);
 
         if (rc) {
-                rc2 = cfs_mem_cache_destroy(lov_oinfo_slab);
-                LASSERT(rc2 == 0);
+               kmem_cache_destroy(lov_oinfo_slab);
                 lu_kmem_fini(lov_caches);
         }
 
@@ -2920,12 +2943,8 @@ int __init lov_init(void)
 #ifdef __KERNEL__
 static void /*__exit*/ lov_exit(void)
 {
-        int rc;
-
-        class_unregister_type(LUSTRE_LOV_NAME);
-        rc = cfs_mem_cache_destroy(lov_oinfo_slab);
-        LASSERT(rc == 0);
-
+       class_unregister_type(LUSTRE_LOV_NAME);
+       kmem_cache_destroy(lov_oinfo_slab);
        lu_kmem_fini(lov_caches);
 }