Whamcloud - gitweb
bdd9681890f3bae47c04b7d170ff4dcbcdcc14dc
[fs/lustre-release.git] / lustre / osc / osc_io.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_io for OSC layer.
37  *
38  *   Author: Nikita Danilov <nikita.danilov@sun.com>
39  */
40
41 /** \addtogroup osc osc @{ */
42
43 #define DEBUG_SUBSYSTEM S_OSC
44
45 #include "osc_cl_internal.h"
46
47 /*****************************************************************************
48  *
49  * Type conversions.
50  *
51  */
52
53 static struct osc_req *cl2osc_req(const struct cl_req_slice *slice)
54 {
55         LINVRNT(slice->crs_dev->cd_lu_dev.ld_type == &osc_device_type);
56         return container_of0(slice, struct osc_req, or_cl);
57 }
58
59 static struct osc_io *cl2osc_io(const struct lu_env *env,
60                                 const struct cl_io_slice *slice)
61 {
62         struct osc_io *oio = container_of0(slice, struct osc_io, oi_cl);
63         LINVRNT(oio == osc_env_io(env));
64         return oio;
65 }
66
67 static struct osc_page *osc_cl_page_osc(struct cl_page *page)
68 {
69         const struct cl_page_slice *slice;
70
71         slice = cl_page_at(page, &osc_device_type);
72         LASSERT(slice != NULL);
73
74         return cl2osc_page(slice);
75 }
76
77
78 /*****************************************************************************
79  *
80  * io operations.
81  *
82  */
83
84 static void osc_io_fini(const struct lu_env *env, const struct cl_io_slice *io)
85 {
86 }
87
88 struct cl_page *osc_oap2cl_page(struct osc_async_page *oap)
89 {
90         return container_of(oap, struct osc_page, ops_oap)->ops_cl.cpl_page;
91 }
92
93 static void osc_io_unplug(const struct lu_env *env, struct osc_object *osc,
94                           struct client_obd *cli)
95 {
96         loi_list_maint(cli, osc->oo_oinfo);
97         osc_check_rpcs(env, cli);
98         client_obd_list_unlock(&cli->cl_loi_list_lock);
99 }
100
101 /**
102  * How many pages osc_io_submit() queues before checking whether an RPC is
103  * ready.
104  */
105 #define OSC_QUEUE_GRAIN (32)
106
107 /**
108  * An implementation of cl_io_operations::cio_io_submit() method for osc
109  * layer. Iterates over pages in the in-queue, prepares each for io by calling
110  * cl_page_prep() and then either submits them through osc_io_submit_page()
111  * or, if page is already submitted, changes osc flags through
112  * osc_set_async_flags_base().
113  */
114 static int osc_io_submit(const struct lu_env *env,
115                          const struct cl_io_slice *ios,
116                          enum cl_req_type crt, struct cl_2queue *queue,
117                          enum cl_req_priority priority)
118 {
119         struct cl_page    *page;
120         struct cl_page    *tmp;
121         struct osc_object *osc0 = NULL;
122         struct client_obd *cli  = NULL;
123         struct osc_object *osc  = NULL; /* to keep gcc happy */
124         struct osc_page   *opg;
125         struct cl_io      *io;
126
127         struct cl_page_list *qin      = &queue->c2_qin;
128         struct cl_page_list *qout     = &queue->c2_qout;
129         int queued = 0;
130         int result = 0;
131
132         LASSERT(qin->pl_nr > 0);
133
134         CDEBUG(D_INFO, "%i %i\n", qin->pl_nr, crt);
135         /*
136          * NOTE: here @page is a top-level page. This is done to avoid
137          *       creation of sub-page-list.
138          */
139         cl_page_list_for_each_safe(page, tmp, qin) {
140                 struct osc_async_page *oap;
141                 struct obd_export     *exp;
142
143                 /* Top level IO. */
144                 io = page->cp_owner;
145                 LASSERT(io != NULL);
146
147                 opg = osc_cl_page_osc(page);
148                 oap = &opg->ops_oap;
149                 osc = cl2osc(opg->ops_cl.cpl_obj);
150                 exp = osc_export(osc);
151
152                 if (priority > CRP_NORMAL) {
153                         spin_lock(&oap->oap_lock);
154                         oap->oap_async_flags |= ASYNC_HP;
155                         spin_unlock(&oap->oap_lock);
156                 }
157                 /*
158                  * This can be checked without cli->cl_loi_list_lock, because
159                  * ->oap_*_item are always manipulated when the page is owned.
160                  */
161                 if (!list_empty(&oap->oap_urgent_item) ||
162                     !list_empty(&oap->oap_rpc_item)) {
163                         result = -EBUSY;
164                         break;
165                 }
166
167                 if (osc0 == NULL) { /* first iteration */
168                         cli = &exp->exp_obd->u.cli;
169                         osc0 = osc;
170                 } else /* check that all pages are against the same object
171                         * (for now) */
172                         LASSERT(osc == osc0);
173                 if (queued++ == 0)
174                         client_obd_list_lock(&cli->cl_loi_list_lock);
175                 result = cl_page_prep(env, io, page, crt);
176                 if (result == 0) {
177                         cl_page_list_move(qout, qin, page);
178                         if (list_empty(&oap->oap_pending_item)) {
179                                 osc_io_submit_page(env, cl2osc_io(env, ios),
180                                                    opg, crt);
181                         } else {
182                                 result = osc_set_async_flags_base(cli,
183                                                                   osc->oo_oinfo,
184                                                                   oap,
185                                                                   OSC_FLAGS);
186                                 /*
187                                  * bug 18881: we can't just break out here when
188                                  * error occurrs after cl_page_prep has been
189                                  * called against the page. The correct
190                                  * way is to call page's completion routine,
191                                  * as in osc_oap_interrupted.  For simplicity,
192                                  * we just force osc_set_async_flags_base() to
193                                  * not return error.
194                                  */
195                                 LASSERT(result == 0);
196                         }
197                 } else {
198                         LASSERT(result < 0);
199                         if (result != -EALREADY)
200                                 break;
201                         /*
202                          * Handle -EALREADY error: for read case, the page is
203                          * already in UPTODATE state; for write, the page
204                          * is not dirty.
205                          */
206                         result = 0;
207                 }
208                 /*
209                  * Don't keep client_obd_list_lock() for too long.
210                  *
211                  * XXX client_obd_list lock has to be unlocked periodically to
212                  * avoid soft-lockups that tend to happen otherwise (see bug
213                  * 16651). On the other hand, osc_io_submit_page() queues a
214                  * page with ASYNC_URGENT flag and so all pages queued up
215                  * until this point are sent out immediately by
216                  * osc_io_unplug() resulting in sub-optimal RPCs (sub-optimal
217                  * RPCs only happen during `warm up' phase when less than
218                  * cl_max_rpcs_in_flight RPCs are in flight). To balance these
219                  * conflicting requirements, one might unplug once enough
220                  * pages to form a large RPC were queued (i.e., use
221                  * cli->cl_max_pages_per_rpc as OSC_QUEUE_GRAIN, see
222                  * lop_makes_rpc()), or ignore soft-lockup issue altogether.
223                  *
224                  * XXX lock_need_resched() should be used here, but it is not
225                  * available in the older of supported kernels.
226                  */
227                 if (queued > OSC_QUEUE_GRAIN || cfs_need_resched()) {
228                         queued = 0;
229                         osc_io_unplug(env, osc, cli);
230                         cfs_cond_resched();
231                 }
232         }
233
234         LASSERT(ergo(result == 0, cli != NULL));
235         LASSERT(ergo(result == 0, osc == osc0));
236
237         if (queued > 0)
238                 osc_io_unplug(env, osc, cli);
239         CDEBUG(D_INFO, "%i/%i %i\n", qin->pl_nr, qout->pl_nr, result);
240         return qout->pl_nr > 0 ? 0 : result;
241 }
242
243 static void osc_page_touch_at(const struct lu_env *env,
244                               struct cl_object *obj, pgoff_t idx, unsigned to)
245 {
246         struct lov_oinfo  *loi  = cl2osc(obj)->oo_oinfo;
247         struct cl_attr    *attr = &osc_env_info(env)->oti_attr;
248         int valid;
249         __u64 kms;
250
251         /* offset within stripe */
252         kms = cl_offset(obj, idx) + to;
253
254         cl_object_attr_lock(obj);
255         /*
256          * XXX old code used
257          *
258          *         ll_inode_size_lock(inode, 0); lov_stripe_lock(lsm);
259          *
260          * here
261          */
262         CDEBUG(D_INODE, "stripe KMS %sincreasing "LPU64"->"LPU64" "LPU64"\n",
263                kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms,
264                loi->loi_lvb.lvb_size);
265
266         valid = 0;
267         if (kms > loi->loi_kms) {
268                 attr->cat_kms = kms;
269                 valid |= CAT_KMS;
270         }
271         if (kms > loi->loi_lvb.lvb_size) {
272                 attr->cat_size = kms;
273                 valid |= CAT_SIZE;
274         }
275         cl_object_attr_set(env, obj, attr, valid);
276         cl_object_attr_unlock(obj);
277 }
278
279 /**
280  * This is called when a page is accessed within file in a way that creates
281  * new page, if one were missing (i.e., if there were a hole at that place in
282  * the file, or accessed page is beyond the current file size). Examples:
283  * ->commit_write() and ->nopage() methods.
284  *
285  * Expand stripe KMS if necessary.
286  */
287 static void osc_page_touch(const struct lu_env *env,
288                            struct osc_page *opage, unsigned to)
289 {
290         struct cl_page    *page = opage->ops_cl.cpl_page;
291         struct cl_object  *obj  = opage->ops_cl.cpl_obj;
292
293         osc_page_touch_at(env, obj, page->cp_index, to);
294 }
295
296 /**
297  * Implements cl_io_operations::cio_prepare_write() method for osc layer.
298  *
299  * \retval -EIO transfer initiated against this osc will most likely fail
300  * \retval 0    transfer initiated against this osc will most likely succeed.
301  *
302  * The reason for this check is to immediately return an error to the caller
303  * in the case of a deactivated import. Note, that import can be deactivated
304  * later, while pages, dirtied by this IO, are still in the cache, but this is
305  * irrelevant, because that would still return an error to the application (if
306  * it does fsync), but many applications don't do fsync because of performance
307  * issues, and we wanted to return an -EIO at write time to notify the
308  * application.
309  */
310 static int osc_io_prepare_write(const struct lu_env *env,
311                                 const struct cl_io_slice *ios,
312                                 const struct cl_page_slice *slice,
313                                 unsigned from, unsigned to)
314 {
315         struct osc_device *dev = lu2osc_dev(slice->cpl_obj->co_lu.lo_dev);
316         struct obd_import *imp = class_exp2cliimp(dev->od_exp);
317
318         ENTRY;
319
320         /*
321          * This implements OBD_BRW_CHECK logic from old client.
322          */
323
324         RETURN(imp == NULL || imp->imp_invalid ? -EIO : 0);
325 }
326
327 static int osc_io_commit_write(const struct lu_env *env,
328                                const struct cl_io_slice *ios,
329                                const struct cl_page_slice *slice,
330                                unsigned from, unsigned to)
331 {
332         struct osc_page       *opg = cl2osc_page(slice);
333         struct osc_object     *obj = cl2osc(opg->ops_cl.cpl_obj);
334         struct osc_async_page *oap = &opg->ops_oap;
335         ENTRY;
336
337         LASSERT(to > 0);
338         /*
339          * XXX instead of calling osc_page_touch() here and in
340          * osc_io_fault_start() it might be more logical to introduce
341          * cl_page_touch() method, that generic cl_io_commit_write() and page
342          * fault code calls.
343          */
344         osc_page_touch(env, cl2osc_page(slice), to);
345         if (!client_is_remote(osc_export(obj)) &&
346             cfs_capable(CFS_CAP_SYS_RESOURCE))
347                 oap->oap_brw_flags |= OBD_BRW_NOQUOTA;
348
349         RETURN(0);
350 }
351
352 static int osc_io_fault_start(const struct lu_env *env,
353                               const struct cl_io_slice *ios)
354 {
355         struct cl_io       *io;
356         struct cl_fault_io *fio;
357
358         ENTRY;
359
360         io  = ios->cis_io;
361         fio = &io->u.ci_fault;
362         CDEBUG(D_INFO, "%lu %i %i\n",
363                fio->ft_index, fio->ft_writable, fio->ft_nob);
364         /*
365          * If mapping is writeable, adjust kms to cover this page,
366          * but do not extend kms beyond actual file size.
367          * See bug 10919.
368          */
369         if (fio->ft_writable)
370                 osc_page_touch_at(env, ios->cis_obj,
371                                   fio->ft_index, fio->ft_nob);
372         RETURN(0);
373 }
374
375 static int osc_punch_upcall(void *a, int rc)
376 {
377         struct osc_punch_cbargs *args = a;
378
379         args->opc_rc = rc;
380         complete(&args->opc_sync);
381         return 0;
382 }
383
384 #ifdef __KERNEL__
385 /**
386  * Checks that there are no pages being written in the extent being truncated.
387  */
388 static void osc_trunc_check(const struct lu_env *env, struct cl_io *io,
389                             struct osc_io *oio, size_t size)
390 {
391         struct osc_page     *cp;
392         struct osc_object   *obj;
393         struct cl_object    *clob;
394         struct cl_page      *page;
395         struct cl_page_list *list;
396         int                  partial;
397         pgoff_t              start;
398
399         clob    = oio->oi_cl.cis_obj;
400         obj     = cl2osc(clob);
401         start   = cl_index(clob, size);
402         partial = cl_offset(clob, start) < size;
403         list    = &osc_env_info(env)->oti_plist;
404
405         /*
406          * Complain if there are pages in the truncated region.
407          *
408          * XXX this is quite expensive check.
409          */
410         cl_page_list_init(list);
411         cl_page_gang_lookup(env, clob, io, start + partial, CL_PAGE_EOF, list);
412
413         cl_page_list_for_each(page, list)
414                 CL_PAGE_DEBUG(D_ERROR, env, page, "exists %lu\n", start);
415
416         cl_page_list_disown(env, io, list);
417         cl_page_list_fini(env, list);
418
419         spin_lock(&obj->oo_seatbelt);
420         list_for_each_entry(cp, &obj->oo_inflight[CRT_WRITE], ops_inflight) {
421                 page = cp->ops_cl.cpl_page;
422                 if (page->cp_index >= start + partial) {
423                         cfs_task_t *submitter;
424
425                         submitter = cp->ops_submitter;
426                         /*
427                          * XXX Linux specific debugging stuff.
428                          */
429                         CL_PAGE_DEBUG(D_ERROR, env, page, "%s/%i %lu\n",
430                                       submitter->comm, submitter->pid, start);
431                         libcfs_debug_dumpstack(submitter);
432                 }
433         }
434         spin_unlock(&obj->oo_seatbelt);
435 }
436 #else /* __KERNEL__ */
437 # define osc_trunc_check(env, io, oio, size) do {;} while (0)
438 #endif
439
440 static int osc_io_trunc_start(const struct lu_env *env,
441                               const struct cl_io_slice *slice)
442 {
443         struct cl_io            *io     = slice->cis_io;
444         struct osc_io           *oio    = cl2osc_io(env, slice);
445         struct cl_object        *obj    = slice->cis_obj;
446         struct lov_oinfo        *loi    = cl2osc(obj)->oo_oinfo;
447         struct cl_attr          *attr   = &osc_env_info(env)->oti_attr;
448         struct obdo             *oa     = &oio->oi_oa;
449         struct osc_punch_cbargs *cbargs = &oio->oi_punch_cbarg;
450         struct obd_capa         *capa;
451         loff_t                   size   = io->u.ci_truncate.tr_size;
452         int                      result = 0;
453
454
455         memset(oa, 0, sizeof(*oa));
456
457         osc_trunc_check(env, io, oio, size);
458
459         if (oio->oi_lockless == 0) {
460                 cl_object_attr_lock(obj);
461                 result = cl_object_attr_get(env, obj, attr);
462                 if (result == 0) {
463                         attr->cat_size = attr->cat_kms = size;
464                         result = cl_object_attr_set(env, obj, attr,
465                                                     CAT_SIZE|CAT_KMS);
466                 }
467                 cl_object_attr_unlock(obj);
468         }
469
470         if (result == 0) {
471                 oa->o_id = loi->loi_id;
472                 oa->o_gr = loi->loi_gr;
473                 oa->o_mtime = attr->cat_mtime;
474                 oa->o_atime = attr->cat_atime;
475                 oa->o_ctime = attr->cat_ctime;
476                 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP | OBD_MD_FLATIME |
477                         OBD_MD_FLCTIME | OBD_MD_FLMTIME;
478                 if (oio->oi_lockless) {
479                         oa->o_flags = OBD_FL_TRUNCLOCK;
480                         oa->o_valid |= OBD_MD_FLFLAGS;
481                 }
482                 oa->o_size = size;
483                 oa->o_blocks = OBD_OBJECT_EOF;
484                 oa->o_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
485
486                 capa = io->u.ci_truncate.tr_capa;
487                 init_completion(&cbargs->opc_sync);
488                 result = osc_punch_base(osc_export(cl2osc(obj)), oa, capa,
489                                         osc_punch_upcall, cbargs, PTLRPCD_SET);
490         }
491         return result;
492 }
493
494 static void osc_io_trunc_end(const struct lu_env *env,
495                              const struct cl_io_slice *slice)
496 {
497         struct cl_io            *io     = slice->cis_io;
498         struct osc_io           *oio    = cl2osc_io(env, slice);
499         struct osc_punch_cbargs *cbargs = &oio->oi_punch_cbarg;
500         struct obdo             *oa     = &oio->oi_oa;
501         int result;
502
503         wait_for_completion(&cbargs->opc_sync);
504
505         result = io->ci_result = cbargs->opc_rc;
506         if (result == 0) {
507                 struct cl_object *obj = slice->cis_obj;
508                 if (oio->oi_lockless == 0) {
509                         struct cl_attr *attr = &osc_env_info(env)->oti_attr;
510                         int valid = 0;
511
512                         /* Update kms & size */
513                         if (oa->o_valid & OBD_MD_FLSIZE) {
514                                 attr->cat_size = oa->o_size;
515                                 attr->cat_kms  = oa->o_size;
516                                 valid |= CAT_KMS|CAT_SIZE;
517                         }
518                         if (oa->o_valid & OBD_MD_FLBLOCKS) {
519                                 attr->cat_blocks = oa->o_blocks;
520                                 valid |= CAT_BLOCKS;
521                         }
522                         if (oa->o_valid & OBD_MD_FLMTIME) {
523                                 attr->cat_mtime = oa->o_mtime;
524                                 valid |= CAT_MTIME;
525                         }
526                         if (oa->o_valid & OBD_MD_FLCTIME) {
527                                 attr->cat_ctime = oa->o_ctime;
528                                 valid |= CAT_CTIME;
529                         }
530                         if (oa->o_valid & OBD_MD_FLATIME) {
531                                 attr->cat_atime = oa->o_atime;
532                                 valid |= CAT_ATIME;
533                         }
534                         cl_object_attr_lock(obj);
535                         result = cl_object_attr_set(env, obj, attr, valid);
536                         cl_object_attr_unlock(obj);
537                 } else {  /* lockless truncate */
538                         struct osc_device *osd = lu2osc_dev(obj->co_lu.lo_dev);
539                         /* XXX: Need a lock. */
540                         osd->od_stats.os_lockless_truncates++;
541                 }
542         }
543
544         /* return result; */
545 }
546
547 static const struct cl_io_operations osc_io_ops = {
548         .op = {
549                 [CIT_READ] = {
550                         .cio_fini   = osc_io_fini
551                 },
552                 [CIT_WRITE] = {
553                         .cio_fini   = osc_io_fini
554                 },
555                 [CIT_TRUNC] = {
556                         .cio_start  = osc_io_trunc_start,
557                         .cio_end    = osc_io_trunc_end
558                 },
559                 [CIT_FAULT] = {
560                         .cio_fini   = osc_io_fini,
561                         .cio_start  = osc_io_fault_start
562                 },
563                 [CIT_MISC] = {
564                         .cio_fini   = osc_io_fini
565                 }
566         },
567         .req_op = {
568                  [CRT_READ] = {
569                          .cio_submit    = osc_io_submit
570                  },
571                  [CRT_WRITE] = {
572                          .cio_submit    = osc_io_submit
573                  }
574          },
575         .cio_prepare_write = osc_io_prepare_write,
576         .cio_commit_write  = osc_io_commit_write
577 };
578
579 /*****************************************************************************
580  *
581  * Transfer operations.
582  *
583  */
584
585 static int osc_req_prep(const struct lu_env *env,
586                         const struct cl_req_slice *slice)
587 {
588         return 0;
589 }
590
591 static void osc_req_completion(const struct lu_env *env,
592                                const struct cl_req_slice *slice, int ioret)
593 {
594         struct osc_req *or;
595
596         or = cl2osc_req(slice);
597         OBD_SLAB_FREE_PTR(or, osc_req_kmem);
598 }
599
600 /**
601  * Implementation of struct cl_req_operations::cro_attr_set() for osc
602  * layer. osc is responsible for struct obdo::o_id and struct obdo::o_gr
603  * fields.
604  */
605 static void osc_req_attr_set(const struct lu_env *env,
606                              const struct cl_req_slice *slice,
607                              const struct cl_object *obj,
608                              struct cl_req_attr *attr, obd_valid flags)
609 {
610         struct lov_oinfo *oinfo;
611         struct cl_req    *clerq;
612         struct cl_page   *apage; /* _some_ page in @clerq */
613         struct cl_lock   *lock;  /* _some_ lock protecting @apage */
614         struct osc_lock  *olck;
615         struct osc_page  *opg;
616         struct obdo      *oa;
617
618         oa = attr->cra_oa;
619         oinfo = cl2osc(obj)->oo_oinfo;
620         if (flags & OBD_MD_FLID) {
621                 oa->o_id = oinfo->loi_id;
622                 oa->o_valid |= OBD_MD_FLID;
623         }
624         if (flags & OBD_MD_FLGROUP) {
625                 oa->o_gr = oinfo->loi_gr;
626                 oa->o_valid |= OBD_MD_FLGROUP;
627         }
628         if (flags & OBD_MD_FLHANDLE) {
629                 clerq = slice->crs_req;
630                 LASSERT(!list_empty(&clerq->crq_pages));
631                 apage = container_of(clerq->crq_pages.next,
632                                      struct cl_page, cp_flight);
633                 opg = osc_cl_page_osc(apage);
634                 apage = opg->ops_cl.cpl_page; /* now apage is a sub-page */
635                 lock = cl_lock_at_page(env, apage->cp_obj, apage, NULL, 1, 1);
636                 LASSERT(lock != NULL);
637                 olck = osc_lock_at(lock);
638                 LASSERT(olck != NULL);
639                 /* check for lockless io. */
640                 if (olck->ols_lock != NULL) {
641                         oa->o_handle = olck->ols_lock->l_remote_handle;
642                         oa->o_valid |= OBD_MD_FLHANDLE;
643                 }
644                 cl_lock_put(env, lock);
645         }
646 }
647
648 static const struct cl_req_operations osc_req_ops = {
649         .cro_prep       = osc_req_prep,
650         .cro_attr_set   = osc_req_attr_set,
651         .cro_completion = osc_req_completion
652 };
653
654
655 int osc_io_init(const struct lu_env *env,
656                 struct cl_object *obj, struct cl_io *io)
657 {
658         struct osc_io *oio = osc_env_io(env);
659
660         CL_IO_SLICE_CLEAN(oio, oi_cl);
661         cl_io_slice_add(io, &oio->oi_cl, obj, &osc_io_ops);
662         return 0;
663 }
664
665 int osc_req_init(const struct lu_env *env, struct cl_device *dev,
666                  struct cl_req *req)
667 {
668         struct osc_req *or;
669         int result;
670
671         OBD_SLAB_ALLOC_PTR_GFP(or, osc_req_kmem, CFS_ALLOC_IO);
672         if (or != NULL) {
673                 cl_req_slice_add(req, &or->or_cl, dev, &osc_req_ops);
674                 result = 0;
675         } else
676                 result = -ENOMEM;
677         return result;
678 }
679
680 /** @} osc */