Whamcloud - gitweb
LU-6401 headers: Create a header for obdo related functions
[fs/lustre-release.git] / lustre / osc / osc_request.c
index b1ade56..f636360 100644 (file)
 
 #include <libcfs/libcfs.h>
 
-#include <lustre_dlm.h>
-#include <lustre_net.h>
 #include <lustre/lustre_user.h>
-#include <obd_cksum.h>
-#include <lustre_ha.h>
+
 #include <lprocfs_status.h>
-#include <lustre_ioctl.h>
 #include <lustre_debug.h>
-#include <lustre_param.h>
+#include <lustre_dlm.h>
 #include <lustre_fid.h>
-#include <obd_class.h>
-#include <obd.h>
+#include <lustre_ha.h>
+#include <lustre_ioctl.h>
 #include <lustre_net.h>
-#include "osc_internal.h"
+#include <lustre_obdo.h>
+#include <lustre_param.h>
+#include <obd.h>
+#include <obd_cksum.h>
+#include <obd_class.h>
+
 #include "osc_cl_internal.h"
+#include "osc_internal.h"
 
 atomic_t osc_pool_req_count;
 unsigned int osc_reqpool_maxreqcount;
@@ -573,7 +575,10 @@ static void osc_announce_cached(struct client_obd *cli, struct obdo *oa,
 
        oa->o_valid |= bits;
        spin_lock(&cli->cl_loi_list_lock);
-       oa->o_dirty = cli->cl_dirty_pages << PAGE_CACHE_SHIFT;
+       if (OCD_HAS_FLAG(&cli->cl_import->imp_connect_data, GRANT_PARAM))
+               oa->o_dirty = cli->cl_dirty_grant;
+       else
+               oa->o_dirty = cli->cl_dirty_pages << PAGE_CACHE_SHIFT;
        if (unlikely(cli->cl_dirty_pages - cli->cl_dirty_transit >
                     cli->cl_dirty_max_pages)) {
                CERROR("dirty %lu - %lu > dirty_max %lu\n",
@@ -597,11 +602,22 @@ static void osc_announce_cached(struct client_obd *cli, struct obdo *oa,
                       cli->cl_dirty_pages, cli->cl_dirty_max_pages);
                oa->o_undirty = 0;
        } else {
-               unsigned long max_in_flight = (cli->cl_max_pages_per_rpc <<
-                                     PAGE_CACHE_SHIFT) *
-                                    (cli->cl_max_rpcs_in_flight + 1);
-               oa->o_undirty = max(cli->cl_dirty_max_pages << PAGE_CACHE_SHIFT,
-                                   max_in_flight);
+               unsigned long nrpages;
+
+               nrpages = cli->cl_max_pages_per_rpc;
+               nrpages *= cli->cl_max_rpcs_in_flight + 1;
+               nrpages = max(nrpages, cli->cl_dirty_max_pages);
+               oa->o_undirty = nrpages << PAGE_CACHE_SHIFT;
+               if (OCD_HAS_FLAG(&cli->cl_import->imp_connect_data,
+                                GRANT_PARAM)) {
+                       int nrextents;
+
+                       /* take extent tax into account when asking for more
+                        * grant space */
+                       nrextents = (nrpages + cli->cl_max_extent_pages - 1)  /
+                                    cli->cl_max_extent_pages;
+                       oa->o_undirty += nrextents * cli->cl_grant_extent_tax;
+               }
         }
        oa->o_grant = cli->cl_avail_grant + cli->cl_reserved_grant;
         oa->o_dropped = cli->cl_lost_grant;
@@ -609,7 +625,6 @@ static void osc_announce_cached(struct client_obd *cli, struct obdo *oa,
        spin_unlock(&cli->cl_loi_list_lock);
         CDEBUG(D_CACHE,"dirty: "LPU64" undirty: %u dropped %u grant: "LPU64"\n",
                oa->o_dirty, oa->o_undirty, oa->o_dropped, oa->o_grant);
-
 }
 
 void osc_update_next_shrink(struct client_obd *cli)
@@ -807,11 +822,15 @@ static void osc_init_grant(struct client_obd *cli, struct obd_connect_data *ocd)
         * left EVICTED state, then cl_dirty_pages must be 0 already.
         */
        spin_lock(&cli->cl_loi_list_lock);
-       if (cli->cl_import->imp_state == LUSTRE_IMP_EVICTED)
-               cli->cl_avail_grant = ocd->ocd_grant;
-       else
-               cli->cl_avail_grant = ocd->ocd_grant -
-                                     (cli->cl_dirty_pages << PAGE_CACHE_SHIFT);
+       cli->cl_avail_grant = ocd->ocd_grant;
+       if (cli->cl_import->imp_state != LUSTRE_IMP_EVICTED) {
+               cli->cl_avail_grant -= cli->cl_reserved_grant;
+               if (OCD_HAS_FLAG(ocd, GRANT_PARAM))
+                       cli->cl_avail_grant -= cli->cl_dirty_grant;
+               else
+                       cli->cl_avail_grant -=
+                                       cli->cl_dirty_pages << PAGE_CACHE_SHIFT;
+       }
 
         if (cli->cl_avail_grant < 0) {
                CWARN("%s: available grant < 0: avail/ocd/dirty %ld/%u/%ld\n",
@@ -822,13 +841,31 @@ static void osc_init_grant(struct client_obd *cli, struct obd_connect_data *ocd)
                cli->cl_avail_grant = ocd->ocd_grant;
         }
 
-       /* determine the appropriate chunk size used by osc_extent. */
-       cli->cl_chunkbits = max_t(int, PAGE_CACHE_SHIFT, ocd->ocd_blocksize);
+       if (OCD_HAS_FLAG(ocd, GRANT_PARAM)) {
+               u64 size;
+
+               /* overhead for each extent insertion */
+               cli->cl_grant_extent_tax = ocd->ocd_grant_tax_kb << 10;
+               /* determine the appropriate chunk size used by osc_extent. */
+               cli->cl_chunkbits = max_t(int, PAGE_CACHE_SHIFT,
+                                         ocd->ocd_grant_blkbits);
+               /* determine maximum extent size, in #pages */
+               size = (u64)ocd->ocd_grant_max_blks << ocd->ocd_grant_blkbits;
+               cli->cl_max_extent_pages = size >> PAGE_CACHE_SHIFT;
+               if (cli->cl_max_extent_pages == 0)
+                       cli->cl_max_extent_pages = 1;
+       } else {
+               cli->cl_grant_extent_tax = 0;
+               cli->cl_chunkbits = PAGE_CACHE_SHIFT;
+               cli->cl_max_extent_pages = DT_MAX_BRW_PAGES;
+       }
        spin_unlock(&cli->cl_loi_list_lock);
 
        CDEBUG(D_CACHE, "%s, setting cl_avail_grant: %ld cl_lost_grant: %ld."
-              "chunk bits: %d.\n", cli_name(cli), cli->cl_avail_grant,
-              cli->cl_lost_grant, cli->cl_chunkbits);
+               "chunk bits: %d cl_max_extent_pages: %d\n",
+               cli_name(cli),
+               cli->cl_avail_grant, cli->cl_lost_grant, cli->cl_chunkbits,
+               cli->cl_max_extent_pages);
 
        if (ocd->ocd_connect_flags & OBD_CONNECT_GRANT_SHRINK &&
            list_empty(&cli->cl_grant_shrink_list))
@@ -1649,6 +1686,7 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
        bool                            soft_sync = false;
        bool                            interrupted = false;
        int                             i;
+       int                             grant = 0;
        int                             rc;
        struct list_head                rpc_list = LIST_HEAD_INIT(rpc_list);
        struct ost_body                 *body;
@@ -1659,6 +1697,7 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
        list_for_each_entry(ext, ext_list, oe_link) {
                LASSERT(ext->oe_state == OES_RPC);
                mem_tight |= ext->oe_memalloc;
+               grant += ext->oe_grants;
                page_count += ext->oe_nr_pages;
                if (obj == NULL)
                        obj = ext->oe_obj;
@@ -1715,6 +1754,9 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
        crattr->cra_oa = oa;
        cl_req_attr_set(env, osc2cl(obj), crattr);
 
+       if (cmd == OBD_BRW_WRITE)
+               oa->o_grant_used = grant;
+
        sort_brw_pages(pga, page_count);
        rc = osc_brw_prep_request(cmd, cli, oa, page_count, pga, &req, 0);
        if (rc != 0) {
@@ -2265,7 +2307,7 @@ static int osc_statfs(const struct lu_env *env, struct obd_export *exp,
 }
 
 static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
-                         void *karg, void *uarg)
+                        void *karg, void __user *uarg)
 {
         struct obd_device *obd = exp->exp_obd;
         struct obd_ioctl_data *data = karg;
@@ -2431,11 +2473,15 @@ static int osc_reconnect(const struct lu_env *env,
 
         if (data != NULL && (data->ocd_connect_flags & OBD_CONNECT_GRANT)) {
                 long lost_grant;
+               long grant;
 
                spin_lock(&cli->cl_loi_list_lock);
-               data->ocd_grant = (cli->cl_avail_grant +
-                                 (cli->cl_dirty_pages << PAGE_CACHE_SHIFT)) ?:
-                                 2 * cli_brw_size(obd);
+               grant = cli->cl_avail_grant + cli->cl_reserved_grant;
+               if (data->ocd_connect_flags & OBD_CONNECT_GRANT_PARAM)
+                       grant += cli->cl_dirty_grant;
+               else
+                       grant += cli->cl_dirty_pages << PAGE_CACHE_SHIFT;
+               data->ocd_grant = grant ? : 2 * cli_brw_size(obd);
                lost_grant = cli->cl_lost_grant;
                cli->cl_lost_grant = 0;
                spin_unlock(&cli->cl_loi_list_lock);
@@ -2533,7 +2579,7 @@ static int osc_import_event(struct obd_device *obd,
         case IMP_EVENT_INVALIDATE: {
                 struct ldlm_namespace *ns = obd->obd_namespace;
                 struct lu_env         *env;
-                int                    refcheck;
+               __u16                  refcheck;
 
                ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
 
@@ -2899,7 +2945,7 @@ out:
        RETURN(rc);
 }
 
-static void /*__exit*/ osc_exit(void)
+static void __exit osc_exit(void)
 {
        remove_shrinker(osc_cache_shrinker);
        class_unregister_type(LUSTRE_OSC_NAME);