Whamcloud - gitweb
b=17167 libcfs: ensure all libcfs exported symbols to have cfs_ prefix
[fs/lustre-release.git] / lustre / osc / osc_page.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * Implementation of cl_page for OSC layer.
37  *
38  *   Author: Nikita Danilov <nikita.danilov@sun.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_OSC
42
43 #include "osc_cl_internal.h"
44
45 /** \addtogroup osc 
46  *  @{ 
47  */
48
49 /* 
50  * Comment out osc_page_protected because it may sleep inside the
51  * the client_obd_list_lock.
52  * client_obd_list_lock -> osc_ap_completion -> osc_completion ->
53  *   -> osc_page_protected -> osc_page_is_dlocked -> osc_match_base
54  *   -> ldlm_lock_match -> sptlrpc_import_check_ctx -> sleep.
55  */
56 #if 0
57 static int osc_page_is_dlocked(const struct lu_env *env,
58                                const struct osc_page *opg,
59                                enum cl_lock_mode mode, int pending, int unref)
60 {
61         struct cl_page         *page;
62         struct osc_object      *obj;
63         struct osc_thread_info *info;
64         struct ldlm_res_id     *resname;
65         struct lustre_handle   *lockh;
66         ldlm_policy_data_t     *policy;
67         ldlm_mode_t             dlmmode;
68         int                     flags;
69
70         cfs_might_sleep();
71
72         info = osc_env_info(env);
73         resname = &info->oti_resname;
74         policy = &info->oti_policy;
75         lockh = &info->oti_handle;
76         page = opg->ops_cl.cpl_page;
77         obj = cl2osc(opg->ops_cl.cpl_obj);
78
79         flags = LDLM_FL_TEST_LOCK | LDLM_FL_BLOCK_GRANTED;
80         if (pending)
81                 flags |= LDLM_FL_CBPENDING;
82
83         dlmmode = osc_cl_lock2ldlm(mode) | LCK_PW;
84         osc_lock_build_res(env, obj, resname);
85         osc_index2policy(policy, page->cp_obj, page->cp_index, page->cp_index);
86         return osc_match_base(osc_export(obj), resname, LDLM_EXTENT, policy,
87                               dlmmode, &flags, NULL, lockh, unref);
88 }
89
90 /**
91  * Checks an invariant that a page in the cache is covered by a lock, as
92  * needed.
93  */
94 static int osc_page_protected(const struct lu_env *env,
95                               const struct osc_page *opg,
96                               enum cl_lock_mode mode, int unref)
97 {
98         struct cl_object_header *hdr;
99         struct cl_lock          *scan;
100         struct cl_page          *page;
101         struct cl_lock_descr    *descr;
102         int result;
103
104         LINVRNT(!opg->ops_temp);
105
106         page = opg->ops_cl.cpl_page;
107         if (page->cp_owner != NULL &&
108             cl_io_top(page->cp_owner)->ci_lockreq == CILR_NEVER)
109                 /*
110                  * If IO is done without locks (liblustre, or lloop), lock is
111                  * not required.
112                  */
113                 result = 1;
114         else
115                 /* otherwise check for a DLM lock */
116         result = osc_page_is_dlocked(env, opg, mode, 1, unref);
117         if (result == 0) {
118                 /* maybe this page is a part of a lockless io? */
119                 hdr = cl_object_header(opg->ops_cl.cpl_obj);
120                 descr = &osc_env_info(env)->oti_descr;
121                 descr->cld_mode = mode;
122                 descr->cld_start = page->cp_index;
123                 descr->cld_end   = page->cp_index;
124                 cfs_spin_lock(&hdr->coh_lock_guard);
125                 cfs_list_for_each_entry(scan, &hdr->coh_locks, cll_linkage) {
126                         /*
127                          * Lock-less sub-lock has to be either in HELD state
128                          * (when io is actively going on), or in CACHED state,
129                          * when top-lock is being unlocked:
130                          * cl_io_unlock()->cl_unuse()->...->lov_lock_unuse().
131                          */
132                         if ((scan->cll_state == CLS_HELD ||
133                              scan->cll_state == CLS_CACHED) &&
134                             cl_lock_ext_match(&scan->cll_descr, descr)) {
135                                 struct osc_lock *olck;
136
137                                 olck = osc_lock_at(scan);
138                                 result = osc_lock_is_lockless(olck);
139                                 break;
140                         }
141                 }
142                 cfs_spin_unlock(&hdr->coh_lock_guard);
143         }
144         return result;
145 }
146 #else
147 static int osc_page_protected(const struct lu_env *env,
148                               const struct osc_page *opg,
149                               enum cl_lock_mode mode, int unref)
150 {
151         return 1;
152 }
153 #endif
154
155 /*****************************************************************************
156  *
157  * Page operations.
158  *
159  */
160 static void osc_page_fini(const struct lu_env *env,
161                           struct cl_page_slice *slice)
162 {
163         struct osc_page *opg = cl2osc_page(slice);
164         CDEBUG(D_TRACE, "%p\n", opg);
165         OBD_SLAB_FREE_PTR(opg, osc_page_kmem);
166 }
167
168 static void osc_page_transfer_get(struct osc_page *opg, const char *label)
169 {
170         struct cl_page *page = cl_page_top(opg->ops_cl.cpl_page);
171
172         LASSERT(!opg->ops_transfer_pinned);
173         cl_page_get(page);
174         lu_ref_add_atomic(&page->cp_reference, label, page);
175         opg->ops_transfer_pinned = 1;
176 }
177
178 static void osc_page_transfer_put(const struct lu_env *env,
179                                   struct osc_page *opg)
180 {
181         struct cl_page *page = cl_page_top(opg->ops_cl.cpl_page);
182
183         if (opg->ops_transfer_pinned) {
184                 lu_ref_del(&page->cp_reference, "transfer", page);
185                 opg->ops_transfer_pinned = 0;
186                 cl_page_put(env, page);
187         }
188 }
189
190 /**
191  * This is called once for every page when it is submitted for a transfer
192  * either opportunistic (osc_page_cache_add()), or immediate
193  * (osc_page_submit()).
194  */
195 static void osc_page_transfer_add(const struct lu_env *env,
196                                   struct osc_page *opg, enum cl_req_type crt)
197 {
198         struct osc_object *obj;
199
200         LINVRNT(cl_page_is_vmlocked(env, opg->ops_cl.cpl_page));
201
202         obj = cl2osc(opg->ops_cl.cpl_obj);
203         cfs_spin_lock(&obj->oo_seatbelt);
204         cfs_list_add(&opg->ops_inflight, &obj->oo_inflight[crt]);
205         opg->ops_submitter = cfs_current();
206         cfs_spin_unlock(&obj->oo_seatbelt);
207 }
208
209 static int osc_page_cache_add(const struct lu_env *env,
210                               const struct cl_page_slice *slice,
211                               struct cl_io *unused)
212 {
213         struct osc_page   *opg = cl2osc_page(slice);
214         struct osc_object *obj = cl2osc(opg->ops_cl.cpl_obj);
215         int result;
216         int brw_flags;
217         int noquota = 0;
218
219         LINVRNT(osc_page_protected(env, opg, CLM_WRITE, 0));
220         ENTRY;
221
222         /* Set the OBD_BRW_SRVLOCK before the page is queued. */
223         brw_flags = opg->ops_srvlock ? OBD_BRW_SRVLOCK : 0;
224         if (!client_is_remote(osc_export(obj)) &&
225             cfs_capable(CFS_CAP_SYS_RESOURCE)) {
226                 brw_flags |= OBD_BRW_NOQUOTA;
227                 noquota = OBD_BRW_NOQUOTA;
228         }
229
230         osc_page_transfer_get(opg, "transfer\0cache");
231         result = osc_queue_async_io(env, osc_export(obj), NULL, obj->oo_oinfo,
232                                     &opg->ops_oap, OBD_BRW_WRITE | noquota,
233                                     0, 0, brw_flags, 0);
234         if (result != 0)
235                 osc_page_transfer_put(env, opg);
236         else
237                 osc_page_transfer_add(env, opg, CRT_WRITE);
238         RETURN(result);
239 }
240
241 void osc_index2policy(ldlm_policy_data_t *policy, const struct cl_object *obj,
242                       pgoff_t start, pgoff_t end)
243 {
244         memset(policy, 0, sizeof *policy);
245         policy->l_extent.start = cl_offset(obj, start);
246         policy->l_extent.end   = cl_offset(obj, end + 1) - 1;
247 }
248
249 static int osc_page_is_under_lock(const struct lu_env *env,
250                                   const struct cl_page_slice *slice,
251                                   struct cl_io *unused)
252 {
253         struct cl_lock *lock;
254         int             result;
255
256         ENTRY;
257         lock = cl_lock_at_page(env, slice->cpl_obj, slice->cpl_page,
258                                NULL, 1, 0);
259         if (lock != NULL) {
260                 cl_lock_put(env, lock);
261                 result = -EBUSY;
262         } else
263                 result = -ENODATA;
264         RETURN(result);
265 }
266
267 static int osc_page_fail(const struct lu_env *env,
268                          const struct cl_page_slice *slice,
269                          struct cl_io *unused)
270 {
271         /*
272          * Cached read?
273          */
274         LBUG();
275         return 0;
276 }
277
278
279 static const char *osc_list(cfs_list_t *head)
280 {
281         return cfs_list_empty(head) ? "-" : "+";
282 }
283
284 static inline cfs_time_t osc_submit_duration(struct osc_page *opg)
285 {
286         if (opg->ops_submit_time == 0)
287                 return 0;
288
289         return (cfs_time_current() - opg->ops_submit_time);
290 }
291
292 static int osc_page_print(const struct lu_env *env,
293                           const struct cl_page_slice *slice,
294                           void *cookie, lu_printer_t printer)
295 {
296         struct osc_page       *opg = cl2osc_page(slice);
297         struct osc_async_page *oap = &opg->ops_oap;
298         struct osc_object     *obj = cl2osc(slice->cpl_obj);
299         struct client_obd     *cli = &osc_export(obj)->exp_obd->u.cli;
300         struct lov_oinfo      *loi = obj->oo_oinfo;
301
302         return (*printer)(env, cookie, LUSTRE_OSC_NAME"-page@%p: "
303                           "1< %#x %d %u %s %s %s > "
304                           "2< %llu %u %#x %#x | %p %p %p %p %p > "
305                           "3< %s %p %d %lu %d > "
306                           "4< %d %d %d %lu %s | %s %s %s %s > "
307                           "5< %s %s %s %s | %d %s %s | %d %s %s>\n",
308                           opg,
309                           /* 1 */
310                           oap->oap_magic, oap->oap_cmd,
311                           oap->oap_interrupted,
312                           osc_list(&oap->oap_pending_item),
313                           osc_list(&oap->oap_urgent_item),
314                           osc_list(&oap->oap_rpc_item),
315                           /* 2 */
316                           oap->oap_obj_off, oap->oap_page_off,
317                           oap->oap_async_flags, oap->oap_brw_flags,
318                           oap->oap_request,
319                           oap->oap_cli, oap->oap_loi, oap->oap_caller_ops,
320                           oap->oap_caller_data,
321                           /* 3 */
322                           osc_list(&opg->ops_inflight),
323                           opg->ops_submitter, opg->ops_transfer_pinned,
324                           osc_submit_duration(opg), opg->ops_srvlock,
325                           /* 4 */
326                           cli->cl_r_in_flight, cli->cl_w_in_flight,
327                           cli->cl_max_rpcs_in_flight,
328                           cli->cl_avail_grant,
329                           osc_list(&cli->cl_cache_waiters),
330                           osc_list(&cli->cl_loi_ready_list),
331                           osc_list(&cli->cl_loi_hp_ready_list),
332                           osc_list(&cli->cl_loi_write_list),
333                           osc_list(&cli->cl_loi_read_list),
334                           /* 5 */
335                           osc_list(&loi->loi_ready_item),
336                           osc_list(&loi->loi_hp_ready_item),
337                           osc_list(&loi->loi_write_item),
338                           osc_list(&loi->loi_read_item),
339                           loi->loi_read_lop.lop_num_pending,
340                           osc_list(&loi->loi_read_lop.lop_pending),
341                           osc_list(&loi->loi_read_lop.lop_urgent),
342                           loi->loi_write_lop.lop_num_pending,
343                           osc_list(&loi->loi_write_lop.lop_pending),
344                           osc_list(&loi->loi_write_lop.lop_urgent));
345 }
346
347 static void osc_page_delete(const struct lu_env *env,
348                             const struct cl_page_slice *slice)
349 {
350         struct osc_page       *opg = cl2osc_page(slice);
351         struct osc_object     *obj = cl2osc(opg->ops_cl.cpl_obj);
352         struct osc_async_page *oap = &opg->ops_oap;
353         int rc;
354
355         LINVRNT(opg->ops_temp || osc_page_protected(env, opg, CLM_READ, 1));
356
357         ENTRY;
358         CDEBUG(D_TRACE, "%p\n", opg);
359         osc_page_transfer_put(env, opg);
360         rc = osc_teardown_async_page(osc_export(obj), NULL, obj->oo_oinfo, oap);
361         if (rc) {
362                 CL_PAGE_DEBUG(D_ERROR, env, cl_page_top(slice->cpl_page),
363                               "Trying to teardown failed: %d\n", rc);
364                 LASSERT(0);
365         }
366         cfs_spin_lock(&obj->oo_seatbelt);
367         cfs_list_del_init(&opg->ops_inflight);
368         cfs_spin_unlock(&obj->oo_seatbelt);
369         EXIT;
370 }
371
372 void osc_page_clip(const struct lu_env *env, const struct cl_page_slice *slice,
373                    int from, int to)
374 {
375         struct osc_page       *opg = cl2osc_page(slice);
376         struct osc_async_page *oap = &opg->ops_oap;
377
378         LINVRNT(osc_page_protected(env, opg, CLM_READ, 0));
379
380         opg->ops_from = from;
381         opg->ops_to   = to;
382         cfs_spin_lock(&oap->oap_lock);
383         oap->oap_async_flags |= ASYNC_COUNT_STABLE;
384         cfs_spin_unlock(&oap->oap_lock);
385 }
386
387 static int osc_page_cancel(const struct lu_env *env,
388                            const struct cl_page_slice *slice)
389 {
390         struct osc_page *opg       = cl2osc_page(slice);
391         struct osc_async_page *oap = &opg->ops_oap;
392         int rc = 0;
393
394         LINVRNT(osc_page_protected(env, opg, CLM_READ, 0));
395
396         client_obd_list_lock(&oap->oap_cli->cl_loi_list_lock);
397         /* Check if the transferring against this page
398          * is completed, or not even queued. */
399         if (opg->ops_transfer_pinned)
400                 /* FIXME: may not be interrupted.. */
401                 rc = osc_oap_interrupted(env, oap);
402         LASSERT(ergo(rc == 0, opg->ops_transfer_pinned == 0));
403         client_obd_list_unlock(&oap->oap_cli->cl_loi_list_lock);
404         return rc;
405 }
406
407 static const struct cl_page_operations osc_page_ops = {
408         .cpo_fini          = osc_page_fini,
409         .cpo_print         = osc_page_print,
410         .cpo_delete        = osc_page_delete,
411         .cpo_is_under_lock = osc_page_is_under_lock,
412         .io = {
413                 [CRT_READ] = {
414                         .cpo_cache_add = osc_page_fail
415                 },
416                 [CRT_WRITE] = {
417                         .cpo_cache_add = osc_page_cache_add
418                 }
419         },
420         .cpo_clip           = osc_page_clip,
421         .cpo_cancel         = osc_page_cancel
422 };
423
424 static int osc_make_ready(const struct lu_env *env, void *data, int cmd)
425 {
426         struct osc_page *opg  = data;
427         struct cl_page  *page = cl_page_top(opg->ops_cl.cpl_page);
428         int result;
429
430         LASSERT(cmd == OBD_BRW_WRITE); /* no cached reads */
431         LINVRNT(osc_page_protected(env, opg, CLM_WRITE, 1));
432
433         ENTRY;
434         result = cl_page_make_ready(env, page, CRT_WRITE);
435         if (result == 0)
436                 opg->ops_submit_time = cfs_time_current();
437         RETURN(result);
438 }
439
440 static int osc_refresh_count(const struct lu_env *env, void *data, int cmd)
441 {
442         struct cl_page   *page;
443         struct osc_page  *osc = data;
444         struct cl_object *obj;
445         struct cl_attr   *attr = &osc_env_info(env)->oti_attr;
446
447         int result;
448         loff_t kms;
449
450         LINVRNT(osc_page_protected(env, osc, CLM_READ, 1));
451
452         /* readpage queues with _COUNT_STABLE, shouldn't get here. */
453         LASSERT(!(cmd & OBD_BRW_READ));
454         LASSERT(osc != NULL);
455         page = osc->ops_cl.cpl_page;
456         obj = osc->ops_cl.cpl_obj;
457
458         cl_object_attr_lock(obj);
459         result = cl_object_attr_get(env, obj, attr);
460         cl_object_attr_unlock(obj);
461         if (result < 0)
462                 return result;
463         kms = attr->cat_kms;
464         if (cl_offset(obj, page->cp_index) >= kms)
465                 /* catch race with truncate */
466                 return 0;
467         else if (cl_offset(obj, page->cp_index + 1) > kms)
468                 /* catch sub-page write at end of file */
469                 return kms % CFS_PAGE_SIZE;
470         else
471                 return CFS_PAGE_SIZE;
472 }
473
474 static int osc_completion(const struct lu_env *env,
475                           void *data, int cmd, struct obdo *oa, int rc)
476 {
477         struct osc_page       *opg  = data;
478         struct osc_async_page *oap  = &opg->ops_oap;
479         struct cl_page        *page = cl_page_top(opg->ops_cl.cpl_page);
480         struct osc_object     *obj  = cl2osc(opg->ops_cl.cpl_obj);
481         enum cl_req_type crt;
482
483         LINVRNT(osc_page_protected(env, opg, CLM_READ, 1));
484         LINVRNT(cl_page_is_vmlocked(env, page));
485
486         ENTRY;
487
488         cmd &= ~OBD_BRW_NOQUOTA;
489         LASSERT(equi(page->cp_state == CPS_PAGEIN,  cmd == OBD_BRW_READ));
490         LASSERT(equi(page->cp_state == CPS_PAGEOUT, cmd == OBD_BRW_WRITE));
491         LASSERT(opg->ops_transfer_pinned);
492
493         /*
494          * page->cp_req can be NULL if io submission failed before
495          * cl_req was allocated.
496          */
497         if (page->cp_req != NULL)
498                 cl_req_page_done(env, page);
499         LASSERT(page->cp_req == NULL);
500
501         /* As the transfer for this page is being done, clear the flags */
502         cfs_spin_lock(&oap->oap_lock);
503         oap->oap_async_flags = 0;
504         cfs_spin_unlock(&oap->oap_lock);
505
506         crt = cmd == OBD_BRW_READ ? CRT_READ : CRT_WRITE;
507         /* Clear opg->ops_transfer_pinned before VM lock is released. */
508         opg->ops_transfer_pinned = 0;
509
510         cfs_spin_lock(&obj->oo_seatbelt);
511         LASSERT(opg->ops_submitter != NULL);
512         LASSERT(!cfs_list_empty(&opg->ops_inflight));
513         cfs_list_del_init(&opg->ops_inflight);
514         cfs_spin_unlock(&obj->oo_seatbelt);
515
516         opg->ops_submit_time = 0;
517
518         cl_page_completion(env, page, crt, rc);
519
520         /* statistic */
521         if (rc == 0 && oap->oap_brw_flags & OBD_BRW_SRVLOCK) {
522                 struct lu_device *ld    = opg->ops_cl.cpl_obj->co_lu.lo_dev;
523                 struct osc_stats *stats = &lu2osc_dev(ld)->od_stats;
524                 int bytes = opg->ops_to - opg->ops_from;
525
526                 if (crt == CRT_READ)
527                         stats->os_lockless_reads += bytes;
528                 else
529                         stats->os_lockless_writes += bytes;
530         }
531
532         /*
533          * This has to be the last operation with the page, as locks are
534          * released in cl_page_completion() and nothing except for the
535          * reference counter protects page from concurrent reclaim.
536          */
537         lu_ref_del(&page->cp_reference, "transfer", page);
538         /*
539          * As page->cp_obj is pinned by a reference from page->cp_req, it is
540          * safe to call cl_page_put() without risking object destruction in a
541          * non-blocking context.
542          */
543         cl_page_put(env, page);
544         RETURN(0);
545 }
546
547 const static struct obd_async_page_ops osc_async_page_ops = {
548         .ap_make_ready    = osc_make_ready,
549         .ap_refresh_count = osc_refresh_count,
550         .ap_completion    = osc_completion
551 };
552
553 struct cl_page *osc_page_init(const struct lu_env *env,
554                               struct cl_object *obj,
555                               struct cl_page *page, cfs_page_t *vmpage)
556 {
557         struct osc_object *osc = cl2osc(obj);
558         struct osc_page   *opg;
559         int result;
560
561         OBD_SLAB_ALLOC_PTR_GFP(opg, osc_page_kmem, CFS_ALLOC_IO);
562         if (opg != NULL) {
563                 void *oap = &opg->ops_oap;
564
565                 opg->ops_from = 0;
566                 opg->ops_to   = CFS_PAGE_SIZE;
567
568                 result = osc_prep_async_page(osc_export(osc),
569                                              NULL, osc->oo_oinfo, vmpage,
570                                              cl_offset(obj, page->cp_index),
571                                              &osc_async_page_ops,
572                                              opg, (void **)&oap, 1, NULL);
573                 if (result == 0) {
574                         struct osc_io *oio = osc_env_io(env);
575                         opg->ops_srvlock = osc_io_srvlock(oio);
576                         cl_page_slice_add(page, &opg->ops_cl, obj,
577                                           &osc_page_ops);
578                 }
579                 /*
580                  * Cannot assert osc_page_protected() here as read-ahead
581                  * creates temporary pages outside of a lock.
582                  */
583 #ifdef INVARIANT_CHECK
584                 opg->ops_temp = !osc_page_protected(env, opg, CLM_READ, 1);
585 #endif
586                 CFS_INIT_LIST_HEAD(&opg->ops_inflight);
587         } else
588                 result = -ENOMEM;
589         return ERR_PTR(result);
590 }
591
592 /**
593  * Helper function called by osc_io_submit() for every page in an immediate
594  * transfer (i.e., transferred synchronously).
595  */
596 void osc_io_submit_page(const struct lu_env *env,
597                         struct osc_io *oio, struct osc_page *opg,
598                         enum cl_req_type crt)
599 {
600         struct osc_async_page *oap = &opg->ops_oap;
601         struct client_obd     *cli = oap->oap_cli;
602         int flags = 0;
603
604         LINVRNT(osc_page_protected(env, opg,
605                                    crt == CRT_WRITE ? CLM_WRITE : CLM_READ, 1));
606
607         oap->oap_page_off   = opg->ops_from;
608         oap->oap_count      = opg->ops_to - opg->ops_from;
609         /* Give a hint to OST that requests are coming from kswapd - bug19529 */
610         if (libcfs_memory_pressure_get())
611                 oap->oap_brw_flags |= OBD_BRW_MEMALLOC;
612         oap->oap_brw_flags |= OBD_BRW_SYNC;
613         if (osc_io_srvlock(oio))
614                 oap->oap_brw_flags |= OBD_BRW_SRVLOCK;
615
616         oap->oap_cmd = crt == CRT_WRITE ? OBD_BRW_WRITE : OBD_BRW_READ;
617         if (!client_is_remote(osc_export(cl2osc(opg->ops_cl.cpl_obj))) &&
618             cfs_capable(CFS_CAP_SYS_RESOURCE)) {
619                 oap->oap_brw_flags |= OBD_BRW_NOQUOTA;
620                 oap->oap_cmd |= OBD_BRW_NOQUOTA;
621         }
622
623         if (oap->oap_cmd & OBD_BRW_READ)
624                 flags = ASYNC_COUNT_STABLE;
625         else if (!(oap->oap_brw_page.flag & OBD_BRW_FROM_GRANT))
626                 osc_enter_cache_try(env, cli, oap->oap_loi, oap, 1);
627
628         cfs_spin_lock(&oap->oap_lock);
629         oap->oap_async_flags |= OSC_FLAGS | flags;
630         cfs_spin_unlock(&oap->oap_lock);
631
632         osc_oap_to_pending(oap);
633         osc_page_transfer_get(opg, "transfer\0imm");
634         osc_page_transfer_add(env, opg, crt);
635 }
636
637 /** @} osc */