Whamcloud - gitweb
LU-5061 obd: add rnb_ prefix to struct niobuf_remote members
[fs/lustre-release.git] / lustre / osc / osc_request.c
index 3416fe3..93567bc 100644 (file)
@@ -503,11 +503,10 @@ int osc_real_create(struct obd_export *exp, struct obdo *oa,
        *ea = lsm;
 
         if (oti != NULL) {
-                oti->oti_transno = lustre_msg_get_transno(req->rq_repmsg);
-
                 if (oa->o_valid & OBD_MD_FLCOOKIE) {
-                        if (!oti->oti_logcookies)
-                                oti_alloc_cookies(oti, 1);
+                       if (oti->oti_logcookies == NULL)
+                               oti->oti_logcookies = &oti->oti_onecookie;
+
                         *oti->oti_logcookies = oa->o_lcookie;
                 }
         }
@@ -659,7 +658,7 @@ static int osc_resource_get_unused(struct obd_export *exp, struct obdo *oa,
 
        ostid_build_res_name(&oa->o_oi, &res_id);
        res = ldlm_resource_get(ns, NULL, &res_id, 0, 0);
-       if (res == NULL)
+       if (IS_ERR(res))
                RETURN(0);
 
         LDLM_RESOURCE_ADDREF(res);
@@ -811,37 +810,38 @@ static void osc_announce_cached(struct client_obd *cli, struct obdo *oa,
 
         LASSERT(!(oa->o_valid & bits));
 
-        oa->o_valid |= bits;
-        client_obd_list_lock(&cli->cl_loi_list_lock);
-        oa->o_dirty = cli->cl_dirty;
-       if (unlikely(cli->cl_dirty - cli->cl_dirty_transit >
-                    cli->cl_dirty_max)) {
+       oa->o_valid |= bits;
+       client_obd_list_lock(&cli->cl_loi_list_lock);
+       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",
-                      cli->cl_dirty, cli->cl_dirty_transit, cli->cl_dirty_max);
+                      cli->cl_dirty_pages, cli->cl_dirty_transit,
+                      cli->cl_dirty_max_pages);
                oa->o_undirty = 0;
-       } else if (unlikely(atomic_read(&obd_unstable_pages) +
-                           atomic_read(&obd_dirty_pages) -
+       } else if (unlikely(atomic_read(&obd_dirty_pages) -
                            atomic_read(&obd_dirty_transit_pages) >
                            (long)(obd_max_dirty_pages + 1))) {
                /* The atomic_read() allowing the atomic_inc() are
                 * not covered by a lock thus they may safely race and trip
                 * this CERROR() unless we add in a small fudge factor (+1). */
-               CERROR("%s: dirty %d + %d - %d > system dirty_max %d\n",
+               CERROR("%s: dirty %d - %d > system dirty_max %d\n",
                       cli->cl_import->imp_obd->obd_name,
-                      atomic_read(&obd_unstable_pages),
                       atomic_read(&obd_dirty_pages),
                       atomic_read(&obd_dirty_transit_pages),
                       obd_max_dirty_pages);
                oa->o_undirty = 0;
-       } else if (unlikely(cli->cl_dirty_max - cli->cl_dirty > 0x7fffffff)) {
+       } else if (unlikely(cli->cl_dirty_max_pages - cli->cl_dirty_pages >
+                           0x7fffffff)) {
                CERROR("dirty %lu - dirty_max %lu too big???\n",
-                      cli->cl_dirty, cli->cl_dirty_max);
+                      cli->cl_dirty_pages, cli->cl_dirty_max_pages);
                oa->o_undirty = 0;
        } else {
                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, max_in_flight);
+               oa->o_undirty = max(cli->cl_dirty_max_pages << PAGE_CACHE_SHIFT,
+                                   max_in_flight);
         }
        oa->o_grant = cli->cl_avail_grant + cli->cl_reserved_grant;
         oa->o_dropped = cli->cl_lost_grant;
@@ -1038,24 +1038,26 @@ static int osc_del_shrink_grant(struct client_obd *client)
 
 static void osc_init_grant(struct client_obd *cli, struct obd_connect_data *ocd)
 {
-        /*
-         * ocd_grant is the total grant amount we're expect to hold: if we've
-         * been evicted, it's the new avail_grant amount, cl_dirty will drop
-         * to 0 as inflight RPCs fail out; otherwise, it's avail_grant + dirty.
-         *
-         * race is tolerable here: if we're evicted, but imp_state already
-         * left EVICTED state, then cl_dirty must be 0 already.
-         */
-        client_obd_list_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;
+       /*
+        * ocd_grant is the total grant amount we're expect to hold: if we've
+        * been evicted, it's the new avail_grant amount, cl_dirty_pages will
+        * drop to 0 as inflight RPCs fail out; otherwise, it's avail_grant +
+        * dirty.
+        *
+        * race is tolerable here: if we're evicted, but imp_state already
+        * left EVICTED state, then cl_dirty_pages must be 0 already.
+        */
+       client_obd_list_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);
 
         if (cli->cl_avail_grant < 0) {
                CWARN("%s: available grant < 0: avail/ocd/dirty %ld/%u/%ld\n",
                      cli->cl_import->imp_obd->obd_name, cli->cl_avail_grant,
-                     ocd->ocd_grant, cli->cl_dirty);
+                     ocd->ocd_grant, cli->cl_dirty_pages << PAGE_CACHE_SHIFT);
                /* workaround for servers which do not have the patch from
                 * LU-2679 */
                cli->cl_avail_grant = ocd->ocd_grant;
@@ -1160,7 +1162,7 @@ static inline int can_merge_pages(struct brw_page *p1, struct brw_page *p2)
                  * safe to combine */
                 if (unlikely((p1->flag & mask) != (p2->flag & mask))) {
                         CWARN("Saw flags 0x%x and 0x%x in the same brw, please "
-                              "report this at http://bugs.whamcloud.com/\n",
+                              "report this at https://jira.hpdd.intel.com/\n",
                               p1->flag, p2->flag);
                 }
                 return 0;
@@ -1198,12 +1200,13 @@ static obd_count osc_checksum_bulk(int nob, obd_count pg_count,
                    OBD_FAIL_CHECK(OBD_FAIL_OSC_CHECKSUM_RECEIVE)) {
                        unsigned char *ptr = kmap(pga[i]->pg);
                        int off = pga[i]->off & ~CFS_PAGE_MASK;
+
                        memcpy(ptr + off, "bad1", min(4, nob));
                        kunmap(pga[i]->pg);
                }
                cfs_crypto_hash_update_page(hdesc, pga[i]->pg,
-                                 pga[i]->off & ~CFS_PAGE_MASK,
-                                 count);
+                                           pga[i]->off & ~CFS_PAGE_MASK,
+                                           count);
                LL_CDEBUG_PAGE(D_PAGE, pga[i]->pg, "off %d\n",
                               (int)(pga[i]->off & ~CFS_PAGE_MASK));
 
@@ -1212,12 +1215,9 @@ static obd_count osc_checksum_bulk(int nob, obd_count pg_count,
                i++;
        }
 
-       bufsize = 4;
+       bufsize = sizeof(cksum);
        err = cfs_crypto_hash_final(hdesc, (unsigned char *)&cksum, &bufsize);
 
-       if (err)
-               cfs_crypto_hash_final(hdesc, NULL, NULL);
-
        /* For sending we only compute the wrong checksum instead
         * of corrupting the data so it is still correct on a redo */
        if (opc == OST_WRITE && OBD_FAIL_CHECK(OBD_FAIL_OSC_CHECKSUM_SEND))
@@ -1344,11 +1344,11 @@ static int osc_brw_prep_request(int cmd, struct client_obd *cli,struct obdo *oa,
 
                 if (i > 0 && can_merge_pages(pg_prev, pg)) {
                         niobuf--;
-                        niobuf->len += pg->count;
-                } else {
-                        niobuf->offset = pg->off;
-                        niobuf->len    = pg->count;
-                        niobuf->flags  = pg->flag;
+                       niobuf->rnb_len += pg->count;
+               } else {
+                       niobuf->rnb_offset = pg->off;
+                       niobuf->rnb_len    = pg->count;
+                       niobuf->rnb_flags  = pg->flag;
                 }
                 pg_prev = pg;
         }
@@ -1835,6 +1835,9 @@ static int brw_interpret(const struct lu_env *env,
        }
        OBDO_FREE(aa->aa_oa);
 
+       if (lustre_msg_get_opc(req->rq_reqmsg) == OST_WRITE && rc == 0)
+               osc_inc_unstable_pages(req);
+
        list_for_each_entry_safe(ext, tmp, &aa->aa_exts, oe_link) {
                list_del_init(&ext->oe_link);
                osc_extent_finish(env, ext, 1, rc);
@@ -1898,13 +1901,13 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
        struct cl_req                   *clerq = NULL;
        enum cl_req_type                crt = (cmd & OBD_BRW_WRITE) ? CRT_WRITE :
                                                                      CRT_READ;
-       struct ldlm_lock                *lock = NULL;
        struct cl_req_attr              *crattr = NULL;
        obd_off                         starting_offset = OBD_OBJECT_EOF;
        obd_off                         ending_offset = 0;
        int                             mpflag = 0;
        int                             mem_tight = 0;
        int                             page_count = 0;
+       bool                            soft_sync = false;
        int                             i;
        int                             rc;
        struct list_head                rpc_list = LIST_HEAD_INIT(rpc_list);
@@ -1932,6 +1935,7 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
                }
        }
 
+       soft_sync = osc_over_unstable_soft_limit(cli);
        if (mem_tight)
                mpflag = cfs_memory_pressure_get_and_set();
 
@@ -1955,10 +1959,11 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
                                             1 /* only 1-object rpcs for now */);
                        if (IS_ERR(clerq))
                                GOTO(out, rc = PTR_ERR(clerq));
-                       lock = oap->oap_ldlm_lock;
                }
                if (mem_tight)
                        oap->oap_brw_flags |= OBD_BRW_MEMALLOC;
+               if (soft_sync)
+                       oap->oap_brw_flags |= OBD_BRW_SOFT_SYNC;
                pga[i] = &oap->oap_brw_page;
                pga[i]->off = oap->oap_obj_off + oap->oap_page_off;
                CDEBUG(0, "put page %p index %lu oap %p flg %x to pga\n",
@@ -1972,10 +1977,6 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
        LASSERT(clerq != NULL);
        crattr->cra_oa = oa;
        cl_req_attr_set(env, clerq, crattr, ~0ULL);
-       if (lock) {
-               oa->o_handle = lock->l_remote_handle;
-               oa->o_valid |= OBD_MD_FLHANDLE;
-       }
 
        rc = cl_req_prep(env, clerq);
        if (rc != 0) {
@@ -2628,7 +2629,8 @@ static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
         ENTRY;
 
        if (!try_module_get(THIS_MODULE)) {
-               CERROR("Can't get module. Is it alive?");
+               CERROR("%s: cannot get module '%s'\n", obd->obd_name,
+                      module_name(THIS_MODULE));
                return -EINVAL;
        }
         switch (cmd) {
@@ -2923,9 +2925,10 @@ static int osc_reconnect(const struct lu_env *env,
         if (data != NULL && (data->ocd_connect_flags & OBD_CONNECT_GRANT)) {
                 long lost_grant;
 
-                client_obd_list_lock(&cli->cl_loi_list_lock);
-                data->ocd_grant = (cli->cl_avail_grant + cli->cl_dirty) ?:
-                               2 * cli_brw_size(obd);
+               client_obd_list_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);
                 lost_grant = cli->cl_lost_grant;
                 cli->cl_lost_grant = 0;
                 client_obd_list_unlock(&cli->cl_loi_list_lock);