Whamcloud - gitweb
LU-1305 lu: fid_is_acct function
[fs/lustre-release.git] / lustre / osc / osc_io.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, Whamcloud, Inc.
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_io 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  *
51  * Type conversions.
52  *
53  */
54
55 static struct osc_req *cl2osc_req(const struct cl_req_slice *slice)
56 {
57         LINVRNT(slice->crs_dev->cd_lu_dev.ld_type == &osc_device_type);
58         return container_of0(slice, struct osc_req, or_cl);
59 }
60
61 static struct osc_io *cl2osc_io(const struct lu_env *env,
62                                 const struct cl_io_slice *slice)
63 {
64         struct osc_io *oio = container_of0(slice, struct osc_io, oi_cl);
65         LINVRNT(oio == osc_env_io(env));
66         return oio;
67 }
68
69 static struct osc_page *osc_cl_page_osc(struct cl_page *page)
70 {
71         const struct cl_page_slice *slice;
72
73         slice = cl_page_at(page, &osc_device_type);
74         LASSERT(slice != NULL);
75
76         return cl2osc_page(slice);
77 }
78
79
80 /*****************************************************************************
81  *
82  * io operations.
83  *
84  */
85
86 static void osc_io_fini(const struct lu_env *env, const struct cl_io_slice *io)
87 {
88 }
89
90 struct cl_page *osc_oap2cl_page(struct osc_async_page *oap)
91 {
92         return container_of(oap, struct osc_page, ops_oap)->ops_cl.cpl_page;
93 }
94
95 static void osc_io_unplug(const struct lu_env *env, struct osc_object *osc,
96                           struct client_obd *cli)
97 {
98         loi_list_maint(cli, osc->oo_oinfo);
99         osc_check_rpcs(env, cli);
100 }
101
102 /**
103  * An implementation of cl_io_operations::cio_io_submit() method for osc
104  * layer. Iterates over pages in the in-queue, prepares each for io by calling
105  * cl_page_prep() and then either submits them through osc_io_submit_page()
106  * or, if page is already submitted, changes osc flags through
107  * osc_set_async_flags_base().
108  */
109 static int osc_io_submit(const struct lu_env *env,
110                          const struct cl_io_slice *ios,
111                          enum cl_req_type crt, struct cl_2queue *queue,
112                          enum cl_req_priority priority)
113 {
114         struct cl_page    *page;
115         struct cl_page    *tmp;
116         struct osc_object *osc0 = NULL;
117         struct client_obd *cli  = NULL;
118         struct osc_object *osc  = NULL; /* to keep gcc happy */
119         struct osc_page   *opg;
120         struct cl_io      *io;
121
122         struct cl_page_list *qin      = &queue->c2_qin;
123         struct cl_page_list *qout     = &queue->c2_qout;
124         int queued = 0;
125         int result = 0;
126
127         LASSERT(qin->pl_nr > 0);
128
129         CDEBUG(D_INFO, "%d %d\n", qin->pl_nr, crt);
130         /*
131          * NOTE: here @page is a top-level page. This is done to avoid
132          *       creation of sub-page-list.
133          */
134         cl_page_list_for_each_safe(page, tmp, qin) {
135                 struct osc_async_page *oap;
136                 struct obd_export     *exp;
137
138                 /* Top level IO. */
139                 io = page->cp_owner;
140                 LASSERT(io != NULL);
141
142                 opg = osc_cl_page_osc(page);
143                 oap = &opg->ops_oap;
144                 osc = cl2osc(opg->ops_cl.cpl_obj);
145                 exp = osc_export(osc);
146
147                 if (priority > CRP_NORMAL) {
148                         cfs_spin_lock(&oap->oap_lock);
149                         oap->oap_async_flags |= ASYNC_HP;
150                         cfs_spin_unlock(&oap->oap_lock);
151                 }
152
153                 if (osc0 == NULL) { /* first iteration */
154                         cli = &exp->exp_obd->u.cli;
155                         osc0 = osc;
156                         client_obd_list_lock(&cli->cl_loi_list_lock);
157                 } else /* check that all pages are against the same object
158                         * (for now) */
159                         LASSERT(osc == osc0);
160
161                 if (!cfs_list_empty(&oap->oap_urgent_item) ||
162                     !cfs_list_empty(&oap->oap_rpc_item)) {
163                         result = -EBUSY;
164                         break;
165                 }
166
167                 result = cl_page_prep(env, io, page, crt);
168                 if (result == 0) {
169                         ++queued;
170                         cl_page_list_move(qout, qin, page);
171                         if (cfs_list_empty(&oap->oap_pending_item)) {
172                                 osc_io_submit_page(env, cl2osc_io(env, ios),
173                                                    opg, crt);
174                         } else {
175                                 result = osc_set_async_flags_base(cli,
176                                                                   osc->oo_oinfo,
177                                                                   oap,
178                                                                   OSC_FLAGS);
179                                 /*
180                                  * bug 18881: we can't just break out here when
181                                  * error occurs after cl_page_prep has been
182                                  * called against the page. The correct
183                                  * way is to call page's completion routine,
184                                  * as in osc_oap_interrupted.  For simplicity,
185                                  * we just force osc_set_async_flags_base() to
186                                  * not return error.
187                                  */
188                                 LASSERT(result == 0);
189                         }
190                         opg->ops_submit_time = cfs_time_current();
191                 } else {
192                         LASSERT(result < 0);
193                         if (result != -EALREADY)
194                                 break;
195                         /*
196                          * Handle -EALREADY error: for read case, the page is
197                          * already in UPTODATE state; for write, the page
198                          * is not dirty.
199                          */
200                         result = 0;
201                 }
202
203                 /*
204                  * We might hold client_obd_list_lock() for too long and cause
205                  * soft-lockups (see bug 16651). But on the other hand, pages
206                  * are queued here with ASYNC_URGENT flag, thus will be sent
207                  * out immediately once osc_io_unplug() be called, possibly
208                  * resulting sub-optimal RPCs.
209                  *
210                  * We think creating optimal-sized RPCs is more important than
211                  * avoiding the transient soft-lockups, plus I believe the
212                  * soft-locks only happen in full debug testing.
213                  */
214         }
215
216         LASSERT(ergo(result == 0, cli != NULL));
217         LASSERT(ergo(result == 0, osc == osc0));
218
219         if (queued > 0)
220                 osc_io_unplug(env, osc, cli);
221         if (osc0)
222                 client_obd_list_unlock(&cli->cl_loi_list_lock);
223         CDEBUG(D_INFO, "%d/%d %d\n", qin->pl_nr, qout->pl_nr, result);
224         return qout->pl_nr > 0 ? 0 : result;
225 }
226
227 static void osc_page_touch_at(const struct lu_env *env,
228                               struct cl_object *obj, pgoff_t idx, unsigned to)
229 {
230         struct lov_oinfo  *loi  = cl2osc(obj)->oo_oinfo;
231         struct cl_attr    *attr = &osc_env_info(env)->oti_attr;
232         int valid;
233         __u64 kms;
234
235         /* offset within stripe */
236         kms = cl_offset(obj, idx) + to;
237
238         cl_object_attr_lock(obj);
239         /*
240          * XXX old code used
241          *
242          *         ll_inode_size_lock(inode, 0); lov_stripe_lock(lsm);
243          *
244          * here
245          */
246         CDEBUG(D_INODE, "stripe KMS %sincreasing "LPU64"->"LPU64" "LPU64"\n",
247                kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms,
248                loi->loi_lvb.lvb_size);
249
250         valid = 0;
251         if (kms > loi->loi_kms) {
252                 attr->cat_kms = kms;
253                 valid |= CAT_KMS;
254         }
255         if (kms > loi->loi_lvb.lvb_size) {
256                 attr->cat_size = kms;
257                 valid |= CAT_SIZE;
258         }
259         cl_object_attr_set(env, obj, attr, valid);
260         cl_object_attr_unlock(obj);
261 }
262
263 /**
264  * This is called when a page is accessed within file in a way that creates
265  * new page, if one were missing (i.e., if there were a hole at that place in
266  * the file, or accessed page is beyond the current file size). Examples:
267  * ->commit_write() and ->nopage() methods.
268  *
269  * Expand stripe KMS if necessary.
270  */
271 static void osc_page_touch(const struct lu_env *env,
272                            struct osc_page *opage, unsigned to)
273 {
274         struct cl_page    *page = opage->ops_cl.cpl_page;
275         struct cl_object  *obj  = opage->ops_cl.cpl_obj;
276
277         osc_page_touch_at(env, obj, page->cp_index, to);
278 }
279
280 /**
281  * Implements cl_io_operations::cio_prepare_write() method for osc layer.
282  *
283  * \retval -EIO transfer initiated against this osc will most likely fail
284  * \retval 0    transfer initiated against this osc will most likely succeed.
285  *
286  * The reason for this check is to immediately return an error to the caller
287  * in the case of a deactivated import. Note, that import can be deactivated
288  * later, while pages, dirtied by this IO, are still in the cache, but this is
289  * irrelevant, because that would still return an error to the application (if
290  * it does fsync), but many applications don't do fsync because of performance
291  * issues, and we wanted to return an -EIO at write time to notify the
292  * application.
293  */
294 static int osc_io_prepare_write(const struct lu_env *env,
295                                 const struct cl_io_slice *ios,
296                                 const struct cl_page_slice *slice,
297                                 unsigned from, unsigned to)
298 {
299         struct osc_device *dev = lu2osc_dev(slice->cpl_obj->co_lu.lo_dev);
300         struct obd_import *imp = class_exp2cliimp(dev->od_exp);
301         struct osc_io     *oio = cl2osc_io(env, ios);
302         int result = 0;
303         ENTRY;
304
305         /*
306          * This implements OBD_BRW_CHECK logic from old client.
307          */
308
309         if (imp == NULL || imp->imp_invalid)
310                 result = -EIO;
311         if (result == 0 && oio->oi_lockless)
312                 /* this page contains `invalid' data, but who cares?
313                  * nobody can access the invalid data.
314                  * in osc_io_commit_write(), we're going to write exact
315                  * [from, to) bytes of this page to OST. -jay */
316                 cl_page_export(env, slice->cpl_page, 1);
317
318         RETURN(result);
319 }
320
321 static int osc_io_commit_write(const struct lu_env *env,
322                                const struct cl_io_slice *ios,
323                                const struct cl_page_slice *slice,
324                                unsigned from, unsigned to)
325 {
326         struct osc_io         *oio = cl2osc_io(env, ios);
327         struct osc_page       *opg = cl2osc_page(slice);
328         struct osc_object     *obj = cl2osc(opg->ops_cl.cpl_obj);
329         struct osc_async_page *oap = &opg->ops_oap;
330         ENTRY;
331
332         LASSERT(to > 0);
333         /*
334          * XXX instead of calling osc_page_touch() here and in
335          * osc_io_fault_start() it might be more logical to introduce
336          * cl_page_touch() method, that generic cl_io_commit_write() and page
337          * fault code calls.
338          */
339         osc_page_touch(env, cl2osc_page(slice), to);
340         if (!client_is_remote(osc_export(obj)) &&
341             cfs_capable(CFS_CAP_SYS_RESOURCE))
342                 oap->oap_brw_flags |= OBD_BRW_NOQUOTA;
343
344         if (oio->oi_lockless)
345                 /* see osc_io_prepare_write() for lockless io handling. */
346                 cl_page_clip(env, slice->cpl_page, from, to);
347
348         RETURN(0);
349 }
350
351 static int osc_io_fault_start(const struct lu_env *env,
352                               const struct cl_io_slice *ios)
353 {
354         struct cl_io       *io;
355         struct cl_fault_io *fio;
356
357         ENTRY;
358
359         io  = ios->cis_io;
360         fio = &io->u.ci_fault;
361         CDEBUG(D_INFO, "%lu %d %d\n",
362                fio->ft_index, fio->ft_writable, fio->ft_nob);
363         /*
364          * If mapping is writeable, adjust kms to cover this page,
365          * but do not extend kms beyond actual file size.
366          * See bug 10919.
367          */
368         if (fio->ft_writable)
369                 osc_page_touch_at(env, ios->cis_obj,
370                                   fio->ft_index, fio->ft_nob);
371         RETURN(0);
372 }
373
374 static int osc_setattr_upcall(void *a, int rc)
375 {
376         struct osc_setattr_cbargs *args = a;
377
378         args->opc_rc = rc;
379         cfs_complete(&args->opc_sync);
380         return 0;
381 }
382
383 /* Disable osc_trunc_check() because it is naturally race between read and
384  * truncate. See bug 20645 for details.
385  */
386 #if 0 && defined(__KERNEL__)
387 /**
388  * Checks that there are no pages being written in the extent being truncated.
389  */
390 static void osc_trunc_check(const struct lu_env *env, struct cl_io *io,
391                             struct osc_io *oio, size_t size)
392 {
393         struct osc_page     *cp;
394         struct osc_object   *obj;
395         struct cl_object    *clob;
396         struct cl_page      *page;
397         struct cl_page_list *list;
398         int                  partial;
399         pgoff_t              start;
400
401         clob    = oio->oi_cl.cis_obj;
402         obj     = cl2osc(clob);
403         start   = cl_index(clob, size);
404         partial = cl_offset(clob, start) < size;
405         list    = &osc_env_info(env)->oti_plist;
406
407         /*
408          * Complain if there are pages in the truncated region.
409          *
410          * XXX this is quite expensive check.
411          */
412         cl_page_list_init(list);
413         cl_page_gang_lookup(env, clob, io, start + partial, CL_PAGE_EOF, list);
414
415         cl_page_list_for_each(page, list)
416                 CL_PAGE_DEBUG(D_ERROR, env, page, "exists %lu\n", start);
417
418         cl_page_list_disown(env, io, list);
419         cl_page_list_fini(env, list);
420
421         cfs_spin_lock(&obj->oo_seatbelt);
422         cfs_list_for_each_entry(cp, &obj->oo_inflight[CRT_WRITE],
423                                 ops_inflight) {
424                 page = cp->ops_cl.cpl_page;
425                 if (page->cp_index >= start + partial) {
426                         cfs_task_t *submitter;
427
428                         submitter = cp->ops_submitter;
429                         /*
430                          * XXX Linux specific debugging stuff.
431                          */
432                         CL_PAGE_DEBUG(D_ERROR, env, page, "%s/%d %lu\n",
433                                       submitter->comm, submitter->pid, start);
434                         libcfs_debug_dumpstack(submitter);
435                 }
436         }
437         cfs_spin_unlock(&obj->oo_seatbelt);
438 }
439 #else /* __KERNEL__ */
440 # define osc_trunc_check(env, io, oio, size) do {;} while (0)
441 #endif
442
443 static int osc_io_setattr_start(const struct lu_env *env,
444                                 const struct cl_io_slice *slice)
445 {
446         struct cl_io            *io     = slice->cis_io;
447         struct osc_io           *oio    = cl2osc_io(env, slice);
448         struct cl_object        *obj    = slice->cis_obj;
449         struct lov_oinfo        *loi    = cl2osc(obj)->oo_oinfo;
450         struct cl_attr          *attr   = &osc_env_info(env)->oti_attr;
451         struct obdo             *oa     = &oio->oi_oa;
452         struct osc_setattr_cbargs *cbargs = &oio->oi_setattr_cbarg;
453         loff_t                   size   = io->u.ci_setattr.sa_attr.lvb_size;
454         unsigned int             ia_valid = io->u.ci_setattr.sa_valid;
455         int                      result = 0;
456         struct obd_info          oinfo = { { { 0 } } };
457
458         if (ia_valid & ATTR_SIZE)
459                 osc_trunc_check(env, io, oio, size);
460
461         if (oio->oi_lockless == 0) {
462                 cl_object_attr_lock(obj);
463                 result = cl_object_attr_get(env, obj, attr);
464                 if (result == 0) {
465                         unsigned int cl_valid = 0;
466
467                         if (ia_valid & ATTR_SIZE) {
468                                 attr->cat_size = attr->cat_kms = size;
469                                 cl_valid = (CAT_SIZE | CAT_KMS);
470                         }
471                         if (ia_valid & ATTR_MTIME_SET) {
472                                 attr->cat_mtime = io->u.ci_setattr.sa_attr.lvb_mtime;
473                                 cl_valid |= CAT_MTIME;
474                         }
475                         if (ia_valid & ATTR_ATIME_SET) {
476                                 attr->cat_atime = io->u.ci_setattr.sa_attr.lvb_atime;
477                                 cl_valid |= CAT_ATIME;
478                         }
479                         if (ia_valid & ATTR_CTIME_SET) {
480                                 attr->cat_ctime = io->u.ci_setattr.sa_attr.lvb_ctime;
481                                 cl_valid |= CAT_CTIME;
482                         }
483                         result = cl_object_attr_set(env, obj, attr, cl_valid);
484                 }
485                 cl_object_attr_unlock(obj);
486         }
487         memset(oa, 0, sizeof(*oa));
488         if (result == 0) {
489                 oa->o_id = loi->loi_id;
490                 oa->o_seq = loi->loi_seq;
491                 oa->o_mtime = attr->cat_mtime;
492                 oa->o_atime = attr->cat_atime;
493                 oa->o_ctime = attr->cat_ctime;
494                 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP | OBD_MD_FLATIME |
495                         OBD_MD_FLCTIME | OBD_MD_FLMTIME;
496                 if (ia_valid & ATTR_SIZE) {
497                         oa->o_size = size;
498                         oa->o_blocks = OBD_OBJECT_EOF;
499                         oa->o_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
500
501                         if (oio->oi_lockless) {
502                                 oa->o_flags = OBD_FL_SRVLOCK;
503                                 oa->o_valid |= OBD_MD_FLFLAGS;
504                         }
505                 } else {
506                         LASSERT(oio->oi_lockless == 0);
507                 }
508
509                 oinfo.oi_oa = oa;
510                 oinfo.oi_capa = io->u.ci_setattr.sa_capa;
511                 cfs_init_completion(&cbargs->opc_sync);
512
513                 if (ia_valid & ATTR_SIZE)
514                         result = osc_punch_base(osc_export(cl2osc(obj)),
515                                                 &oinfo, osc_setattr_upcall,
516                                                 cbargs, PTLRPCD_SET);
517                 else
518                         result = osc_setattr_async_base(osc_export(cl2osc(obj)),
519                                                         &oinfo, NULL,
520                                                         osc_setattr_upcall,
521                                                         cbargs, PTLRPCD_SET);
522         }
523         return result;
524 }
525
526 static void osc_io_setattr_end(const struct lu_env *env,
527                                const struct cl_io_slice *slice)
528 {
529         struct cl_io            *io     = slice->cis_io;
530         struct osc_io           *oio    = cl2osc_io(env, slice);
531         struct osc_setattr_cbargs *cbargs = &oio->oi_setattr_cbarg;
532         int result;
533
534         cfs_wait_for_completion(&cbargs->opc_sync);
535
536         result = io->ci_result = cbargs->opc_rc;
537         if (result == 0) {
538                 struct cl_object *obj = slice->cis_obj;
539                 if (oio->oi_lockless) {
540                         /* lockless truncate */
541                         struct osc_device *osd = lu2osc_dev(obj->co_lu.lo_dev);
542
543                         LASSERT(cl_io_is_trunc(io));
544                         /* XXX: Need a lock. */
545                         osd->od_stats.os_lockless_truncates++;
546                 }
547         }
548 }
549
550 static int osc_io_read_start(const struct lu_env *env,
551                              const struct cl_io_slice *slice)
552 {
553         struct osc_io    *oio   = cl2osc_io(env, slice);
554         struct cl_object *obj   = slice->cis_obj;
555         struct cl_attr   *attr  = &osc_env_info(env)->oti_attr;
556         int              result = 0;
557         ENTRY;
558
559         if (oio->oi_lockless == 0) {
560                 cl_object_attr_lock(obj);
561                 result = cl_object_attr_get(env, obj, attr);
562                 if (result == 0) {
563                         attr->cat_atime = LTIME_S(CFS_CURRENT_TIME);
564                         result = cl_object_attr_set(env, obj, attr,
565                                                     CAT_ATIME);
566                 }
567                 cl_object_attr_unlock(obj);
568         }
569         RETURN(result);
570 }
571
572 static int osc_io_write_start(const struct lu_env *env,
573                               const struct cl_io_slice *slice)
574 {
575         struct osc_io    *oio   = cl2osc_io(env, slice);
576         struct cl_object *obj   = slice->cis_obj;
577         struct cl_attr   *attr  = &osc_env_info(env)->oti_attr;
578         int              result = 0;
579         ENTRY;
580
581         if (oio->oi_lockless == 0) {
582                 cl_object_attr_lock(obj);
583                 result = cl_object_attr_get(env, obj, attr);
584                 if (result == 0) {
585                         attr->cat_mtime = attr->cat_ctime =
586                                 LTIME_S(CFS_CURRENT_TIME);
587                         result = cl_object_attr_set(env, obj, attr,
588                                                     CAT_MTIME | CAT_CTIME);
589                 }
590                 cl_object_attr_unlock(obj);
591         }
592         RETURN(result);
593 }
594
595 static const struct cl_io_operations osc_io_ops = {
596         .op = {
597                 [CIT_READ] = {
598                         .cio_start  = osc_io_read_start,
599                         .cio_fini   = osc_io_fini
600                 },
601                 [CIT_WRITE] = {
602                         .cio_start  = osc_io_write_start,
603                         .cio_fini   = osc_io_fini
604                 },
605                 [CIT_SETATTR] = {
606                         .cio_start  = osc_io_setattr_start,
607                         .cio_end    = osc_io_setattr_end
608                 },
609                 [CIT_FAULT] = {
610                         .cio_fini   = osc_io_fini,
611                         .cio_start  = osc_io_fault_start
612                 },
613                 [CIT_MISC] = {
614                         .cio_fini   = osc_io_fini
615                 }
616         },
617         .req_op = {
618                  [CRT_READ] = {
619                          .cio_submit    = osc_io_submit
620                  },
621                  [CRT_WRITE] = {
622                          .cio_submit    = osc_io_submit
623                  }
624          },
625         .cio_prepare_write = osc_io_prepare_write,
626         .cio_commit_write  = osc_io_commit_write
627 };
628
629 /*****************************************************************************
630  *
631  * Transfer operations.
632  *
633  */
634
635 static int osc_req_prep(const struct lu_env *env,
636                         const struct cl_req_slice *slice)
637 {
638         return 0;
639 }
640
641 static void osc_req_completion(const struct lu_env *env,
642                                const struct cl_req_slice *slice, int ioret)
643 {
644         struct osc_req *or;
645
646         or = cl2osc_req(slice);
647         OBD_SLAB_FREE_PTR(or, osc_req_kmem);
648 }
649
650 /**
651  * Implementation of struct cl_req_operations::cro_attr_set() for osc
652  * layer. osc is responsible for struct obdo::o_id and struct obdo::o_seq
653  * fields.
654  */
655 static void osc_req_attr_set(const struct lu_env *env,
656                              const struct cl_req_slice *slice,
657                              const struct cl_object *obj,
658                              struct cl_req_attr *attr, obd_valid flags)
659 {
660         struct lov_oinfo *oinfo;
661         struct cl_req    *clerq;
662         struct cl_page   *apage; /* _some_ page in @clerq */
663         struct cl_lock   *lock;  /* _some_ lock protecting @apage */
664         struct osc_lock  *olck;
665         struct osc_page  *opg;
666         struct obdo      *oa;
667
668         oa = attr->cra_oa;
669         oinfo = cl2osc(obj)->oo_oinfo;
670         if (flags & OBD_MD_FLID) {
671                 oa->o_id = oinfo->loi_id;
672                 oa->o_valid |= OBD_MD_FLID;
673         }
674         if (flags & OBD_MD_FLGROUP) {
675                 oa->o_seq = oinfo->loi_seq;
676                 oa->o_valid |= OBD_MD_FLGROUP;
677         }
678         if (flags & OBD_MD_FLHANDLE) {
679                 clerq = slice->crs_req;
680                 LASSERT(!cfs_list_empty(&clerq->crq_pages));
681                 apage = container_of(clerq->crq_pages.next,
682                                      struct cl_page, cp_flight);
683                 opg = osc_cl_page_osc(apage);
684                 apage = opg->ops_cl.cpl_page; /* now apage is a sub-page */
685                 lock = cl_lock_at_page(env, apage->cp_obj, apage, NULL, 1, 1);
686                 if (lock == NULL) {
687                         struct cl_object_header *head;
688                         struct cl_lock          *scan;
689
690                         head = cl_object_header(apage->cp_obj);
691                         cfs_list_for_each_entry(scan, &head->coh_locks,
692                                                 cll_linkage)
693                                 CL_LOCK_DEBUG(D_ERROR, env, scan,
694                                               "no cover page!\n");
695                         CL_PAGE_DEBUG(D_ERROR, env, apage,
696                                       "dump uncover page!\n");
697                         libcfs_debug_dumpstack(NULL);
698                         LBUG();
699                 }
700
701                 olck = osc_lock_at(lock);
702                 LASSERT(olck != NULL);
703                 LASSERT(ergo(opg->ops_srvlock, olck->ols_lock == NULL));
704                 /* check for lockless io. */
705                 if (olck->ols_lock != NULL) {
706                         oa->o_handle = olck->ols_lock->l_remote_handle;
707                         oa->o_valid |= OBD_MD_FLHANDLE;
708                 }
709                 cl_lock_put(env, lock);
710         }
711 }
712
713 static const struct cl_req_operations osc_req_ops = {
714         .cro_prep       = osc_req_prep,
715         .cro_attr_set   = osc_req_attr_set,
716         .cro_completion = osc_req_completion
717 };
718
719
720 int osc_io_init(const struct lu_env *env,
721                 struct cl_object *obj, struct cl_io *io)
722 {
723         struct osc_io *oio = osc_env_io(env);
724
725         CL_IO_SLICE_CLEAN(oio, oi_cl);
726         cl_io_slice_add(io, &oio->oi_cl, obj, &osc_io_ops);
727         return 0;
728 }
729
730 int osc_req_init(const struct lu_env *env, struct cl_device *dev,
731                  struct cl_req *req)
732 {
733         struct osc_req *or;
734         int result;
735
736         OBD_SLAB_ALLOC_PTR_GFP(or, osc_req_kmem, CFS_ALLOC_IO);
737         if (or != NULL) {
738                 cl_req_slice_add(req, &or->or_cl, dev, &osc_req_ops);
739                 result = 0;
740         } else
741                 result = -ENOMEM;
742         return result;
743 }
744
745 /** @} osc */