1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
5 * Author Peter Braam <braam@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * For testing and management it is treated as an obd_device,
23 * although * it does not export a full OBD method table (the
24 * requests are coming * in over the wire, so object target modules
25 * do not have a full * method table.)
30 # define EXPORT_SYMTAB
32 #define DEBUG_SUBSYSTEM S_OSC
35 # include <linux/version.h>
36 # include <linux/module.h>
37 # include <linux/mm.h>
38 # include <linux/highmem.h>
39 # include <linux/ctype.h>
40 # include <linux/init.h>
41 # if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
42 # include <linux/workqueue.h>
43 # include <linux/smp_lock.h>
45 # include <linux/locks.h>
47 #else /* __KERNEL__ */
48 # include <liblustre.h>
51 # include <linux/lustre_dlm.h>
52 #include <linux/kp30.h>
53 #include <linux/lustre_net.h>
54 #include <lustre/lustre_user.h>
55 #include <linux/obd_ost.h>
56 #include <linux/obd_lov.h>
62 #include <linux/lustre_ha.h>
63 #include <linux/lprocfs_status.h>
64 #include <linux/lustre_log.h>
65 #include "osc_internal.h"
67 /* Pack OSC object metadata for disk storage (LE byte order). */
68 static int osc_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
69 struct lov_stripe_md *lsm)
74 lmm_size = sizeof(**lmmp);
79 OBD_FREE(*lmmp, lmm_size);
85 OBD_ALLOC(*lmmp, lmm_size);
91 LASSERT(lsm->lsm_object_id);
92 (*lmmp)->lmm_object_id = cpu_to_le64(lsm->lsm_object_id);
98 /* Unpack OSC object metadata from disk storage (LE byte order). */
99 static int osc_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
100 struct lov_mds_md *lmm, int lmm_bytes)
106 if (lmm_bytes < sizeof (*lmm)) {
107 CERROR("lov_mds_md too small: %d, need %d\n",
108 lmm_bytes, (int)sizeof(*lmm));
111 /* XXX LOV_MAGIC etc check? */
113 if (lmm->lmm_object_id == 0) {
114 CERROR("lov_mds_md: zero lmm_object_id\n");
119 lsm_size = lov_stripe_md_size(1);
123 if (*lsmp != NULL && lmm == NULL) {
124 OBD_FREE(*lsmp, lsm_size);
130 OBD_ALLOC(*lsmp, lsm_size);
133 loi_init((*lsmp)->lsm_oinfo);
137 /* XXX zero *lsmp? */
138 (*lsmp)->lsm_object_id = le64_to_cpu (lmm->lmm_object_id);
139 LASSERT((*lsmp)->lsm_object_id);
142 (*lsmp)->lsm_maxbytes = LUSTRE_STRIPE_MAXBYTES;
147 static int osc_getattr_interpret(struct ptlrpc_request *req,
148 struct osc_getattr_async_args *aa, int rc)
150 struct ost_body *body;
156 body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
158 CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
159 memcpy(aa->aa_oa, &body->oa, sizeof(*aa->aa_oa));
161 /* This should really be sent by the OST */
162 aa->aa_oa->o_blksize = PTLRPC_MAX_BRW_SIZE;
163 aa->aa_oa->o_valid |= OBD_MD_FLBLKSZ;
165 CERROR("can't unpack ost_body\n");
167 aa->aa_oa->o_valid = 0;
173 static int osc_getattr_async(struct obd_export *exp, struct obdo *oa,
174 struct lov_stripe_md *md,
175 struct ptlrpc_request_set *set)
177 struct ptlrpc_request *request;
178 struct ost_body *body;
179 int size = sizeof(*body);
180 struct osc_getattr_async_args *aa;
183 request = ptlrpc_prep_req(class_exp2cliimp(exp), OST_GETATTR, 1,
188 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
189 memcpy(&body->oa, oa, sizeof(*oa));
191 request->rq_replen = lustre_msg_size(1, &size);
192 request->rq_interpret_reply = osc_getattr_interpret;
194 LASSERT (sizeof (*aa) <= sizeof (request->rq_async_args));
195 aa = (struct osc_getattr_async_args *)&request->rq_async_args;
198 ptlrpc_set_add_req (set, request);
202 static int osc_getattr(struct obd_export *exp, struct obdo *oa,
203 struct lov_stripe_md *md)
205 struct ptlrpc_request *request;
206 struct ost_body *body;
207 int rc, size = sizeof(*body);
210 request = ptlrpc_prep_req(class_exp2cliimp(exp), OST_GETATTR, 1,
215 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
216 memcpy(&body->oa, oa, sizeof(*oa));
218 request->rq_replen = lustre_msg_size(1, &size);
220 rc = ptlrpc_queue_wait(request);
222 CERROR("%s failed: rc = %d\n", __FUNCTION__, rc);
226 body = lustre_swab_repbuf(request, 0, sizeof (*body),
227 lustre_swab_ost_body);
229 CERROR ("can't unpack ost_body\n");
230 GOTO (out, rc = -EPROTO);
233 CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
234 memcpy(oa, &body->oa, sizeof(*oa));
236 /* This should really be sent by the OST */
237 oa->o_blksize = PTLRPC_MAX_BRW_SIZE;
238 oa->o_valid |= OBD_MD_FLBLKSZ;
242 ptlrpc_req_finished(request);
246 static int osc_setattr(struct obd_export *exp, struct obdo *oa,
247 struct lov_stripe_md *md, struct obd_trans_info *oti)
249 struct ptlrpc_request *request;
250 struct ost_body *body;
251 int rc, size = sizeof(*body);
254 request = ptlrpc_prep_req(class_exp2cliimp(exp), OST_SETATTR, 1, &size,
259 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof(*body));
260 memcpy(&body->oa, oa, sizeof(*oa));
262 request->rq_replen = lustre_msg_size(1, &size);
264 rc = ptlrpc_queue_wait(request);
268 body = lustre_swab_repbuf(request, 0, sizeof(*body),
269 lustre_swab_ost_body);
271 GOTO(out, rc = -EPROTO);
273 memcpy(oa, &body->oa, sizeof(*oa));
277 ptlrpc_req_finished(request);
281 int osc_real_create(struct obd_export *exp, struct obdo *oa,
282 struct lov_stripe_md **ea, struct obd_trans_info *oti)
284 struct ptlrpc_request *request;
285 struct ost_body *body;
286 struct lov_stripe_md *lsm;
287 int rc, size = sizeof(*body);
295 rc = obd_alloc_memmd(exp, &lsm);
300 request = ptlrpc_prep_req(class_exp2cliimp(exp), OST_CREATE, 1, &size,
303 GOTO(out, rc = -ENOMEM);
305 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
306 memcpy(&body->oa, oa, sizeof(body->oa));
308 request->rq_replen = lustre_msg_size(1, &size);
309 if (oa->o_valid & OBD_MD_FLINLINE) {
310 LASSERT((oa->o_valid & OBD_MD_FLFLAGS) &&
311 oa->o_flags == OBD_FL_DELORPHAN);
312 DEBUG_REQ(D_HA, request,
313 "delorphan from OST integration");
314 /* Don't resend the delorphan request */
315 request->rq_no_resend = request->rq_no_delay = 1;
318 rc = ptlrpc_queue_wait(request);
322 body = lustre_swab_repbuf(request, 0, sizeof(*body),
323 lustre_swab_ost_body);
325 CERROR ("can't unpack ost_body\n");
326 GOTO (out_req, rc = -EPROTO);
329 memcpy(oa, &body->oa, sizeof(*oa));
331 /* This should really be sent by the OST */
332 oa->o_blksize = PTLRPC_MAX_BRW_SIZE;
333 oa->o_valid |= OBD_MD_FLBLKSZ;
335 /* XXX LOV STACKING: the lsm that is passed to us from LOV does not
336 * have valid lsm_oinfo data structs, so don't go touching that.
337 * This needs to be fixed in a big way.
339 lsm->lsm_object_id = oa->o_id;
343 oti->oti_transno = request->rq_repmsg->transno;
345 if (oa->o_valid & OBD_MD_FLCOOKIE) {
346 if (!oti->oti_logcookies)
347 oti_alloc_cookies(oti, 1);
348 memcpy(oti->oti_logcookies, obdo_logcookie(oa),
349 sizeof(oti->oti_onecookie));
353 CDEBUG(D_HA, "transno: "LPD64"\n", request->rq_repmsg->transno);
356 ptlrpc_req_finished(request);
359 obd_free_memmd(exp, &lsm);
363 static int osc_punch(struct obd_export *exp, struct obdo *oa,
364 struct lov_stripe_md *md, obd_size start,
365 obd_size end, struct obd_trans_info *oti)
367 struct ptlrpc_request *request;
368 struct ost_body *body;
369 int rc, size = sizeof(*body);
377 request = ptlrpc_prep_req(class_exp2cliimp(exp), OST_PUNCH, 1, &size,
382 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
383 memcpy(&body->oa, oa, sizeof(*oa));
385 /* overload the size and blocks fields in the oa with start/end */
386 body->oa.o_size = start;
387 body->oa.o_blocks = end;
388 body->oa.o_valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
390 request->rq_replen = lustre_msg_size(1, &size);
392 rc = ptlrpc_queue_wait(request);
396 body = lustre_swab_repbuf (request, 0, sizeof (*body),
397 lustre_swab_ost_body);
399 CERROR ("can't unpack ost_body\n");
400 GOTO (out, rc = -EPROTO);
403 memcpy(oa, &body->oa, sizeof(*oa));
407 ptlrpc_req_finished(request);
411 static int osc_sync(struct obd_export *exp, struct obdo *oa,
412 struct lov_stripe_md *md, obd_size start, obd_size end)
414 struct ptlrpc_request *request;
415 struct ost_body *body;
416 int rc, size = sizeof(*body);
424 request = ptlrpc_prep_req(class_exp2cliimp(exp), OST_SYNC, 1, &size,
429 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
430 memcpy(&body->oa, oa, sizeof(*oa));
432 /* overload the size and blocks fields in the oa with start/end */
433 body->oa.o_size = start;
434 body->oa.o_blocks = end;
435 body->oa.o_valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
437 request->rq_replen = lustre_msg_size(1, &size);
439 rc = ptlrpc_queue_wait(request);
443 body = lustre_swab_repbuf(request, 0, sizeof(*body),
444 lustre_swab_ost_body);
446 CERROR ("can't unpack ost_body\n");
447 GOTO (out, rc = -EPROTO);
450 memcpy(oa, &body->oa, sizeof(*oa));
454 ptlrpc_req_finished(request);
458 static int osc_destroy(struct obd_export *exp, struct obdo *oa,
459 struct lov_stripe_md *ea, struct obd_trans_info *oti)
461 struct ptlrpc_request *request;
462 struct ost_body *body;
463 int rc, size = sizeof(*body);
471 request = ptlrpc_prep_req(class_exp2cliimp(exp), OST_DESTROY, 1,
476 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
478 if (oti != NULL && oa->o_valid & OBD_MD_FLCOOKIE) {
479 memcpy(obdo_logcookie(oa), oti->oti_logcookies,
480 sizeof(*oti->oti_logcookies));
481 oti->oti_logcookies++;
484 memcpy(&body->oa, oa, sizeof(*oa));
485 request->rq_replen = lustre_msg_size(1, &size);
487 rc = ptlrpc_queue_wait(request);
493 body = lustre_swab_repbuf(request, 0, sizeof(*body),
494 lustre_swab_ost_body);
496 CERROR ("Can't unpack body\n");
497 GOTO (out, rc = -EPROTO);
500 memcpy(oa, &body->oa, sizeof(*oa));
504 ptlrpc_req_finished(request);
508 static void osc_announce_cached(struct client_obd *cli, struct obdo *oa,
511 obd_flag bits = OBD_MD_FLBLOCKS|OBD_MD_FLGRANT;
513 LASSERT(!(oa->o_valid & bits));
516 spin_lock(&cli->cl_loi_list_lock);
517 oa->o_dirty = cli->cl_dirty;
518 if (cli->cl_dirty > cli->cl_dirty_max) {
519 CERROR("dirty %lu > dirty_max %lu\n",
520 cli->cl_dirty, cli->cl_dirty_max);
522 } else if (cli->cl_dirty_max - cli->cl_dirty > 0x7fffffff) {
523 CERROR("dirty %lu - dirty_max %lu too big???\n",
524 cli->cl_dirty, cli->cl_dirty_max);
527 oa->o_undirty = cli->cl_dirty_max - oa->o_dirty;
529 oa->o_grant = cli->cl_avail_grant;
530 oa->o_dropped = cli->cl_lost_grant;
531 cli->cl_lost_grant = 0;
532 spin_unlock(&cli->cl_loi_list_lock);
533 CDEBUG(D_CACHE,"dirty: "LPU64" undirty: %u dropped %u grant: "LPU64"\n",
534 oa->o_dirty, oa->o_undirty, oa->o_dropped, oa->o_grant);
537 /* caller must hold loi_list_lock */
538 static void osc_consume_write_grant(struct client_obd *cli,
539 struct osc_async_page *oap)
541 cli->cl_dirty += PAGE_SIZE;
542 cli->cl_avail_grant -= PAGE_SIZE;
543 oap->oap_brw_flags |= OBD_BRW_FROM_GRANT;
544 CDEBUG(D_CACHE, "using %lu grant credits for oap %p\n", PAGE_SIZE, oap);
545 LASSERT(cli->cl_avail_grant >= 0);
548 static unsigned long rpcs_in_flight(struct client_obd *cli)
550 return cli->cl_r_in_flight + cli->cl_w_in_flight;
553 /* caller must hold loi_list_lock */
554 void osc_wake_cache_waiters(struct client_obd *cli)
556 struct list_head *l, *tmp;
557 struct osc_cache_waiter *ocw;
559 list_for_each_safe(l, tmp, &cli->cl_cache_waiters) {
560 /* if we can't dirty more, we must wait until some is written */
561 if (cli->cl_dirty + PAGE_SIZE > cli->cl_dirty_max) {
562 CDEBUG(D_CACHE, "no dirty room: dirty: %ld max %ld\n",
563 cli->cl_dirty, cli->cl_dirty_max);
567 /* if still dirty cache but no grant wait for pending RPCs that
568 * may yet return us some grant before doing sync writes */
569 if (cli->cl_w_in_flight && cli->cl_avail_grant < PAGE_SIZE) {
570 CDEBUG(D_CACHE, "%u BRW writes in flight, no grant\n",
571 cli->cl_w_in_flight);
575 ocw = list_entry(l, struct osc_cache_waiter, ocw_entry);
576 list_del_init(&ocw->ocw_entry);
577 if (cli->cl_avail_grant < PAGE_SIZE) {
578 /* no more RPCs in flight to return grant, do sync IO */
579 ocw->ocw_rc = -EDQUOT;
580 CDEBUG(D_INODE, "wake oap %p for sync\n", ocw->ocw_oap);
582 osc_consume_write_grant(cli, ocw->ocw_oap);
585 wake_up(&ocw->ocw_waitq);
591 static void osc_update_grant(struct client_obd *cli, struct ost_body *body)
593 spin_lock(&cli->cl_loi_list_lock);
594 CDEBUG(D_CACHE, "got "LPU64" extra grant\n", body->oa.o_grant);
595 cli->cl_avail_grant += body->oa.o_grant;
596 /* waiters are woken in brw_interpret_oap */
597 spin_unlock(&cli->cl_loi_list_lock);
600 /* We assume that the reason this OSC got a short read is because it read
601 * beyond the end of a stripe file; i.e. lustre is reading a sparse file
602 * via the LOV, and it _knows_ it's reading inside the file, it's just that
603 * this stripe never got written at or beyond this stripe offset yet. */
604 static void handle_short_read(int nob_read, obd_count page_count,
605 struct brw_page *pga)
609 /* skip bytes read OK */
610 while (nob_read > 0) {
611 LASSERT (page_count > 0);
613 if (pga->count > nob_read) {
614 /* EOF inside this page */
615 ptr = kmap(pga->pg) + (pga->off & ~PAGE_MASK);
616 memset(ptr + nob_read, 0, pga->count - nob_read);
623 nob_read -= pga->count;
628 /* zero remaining pages */
629 while (page_count-- > 0) {
630 ptr = kmap(pga->pg) + (pga->off & ~PAGE_MASK);
631 memset(ptr, 0, pga->count);
637 static int check_write_rcs(struct ptlrpc_request *request,
638 int requested_nob, int niocount,
639 obd_count page_count, struct brw_page *pga)
643 /* return error if any niobuf was in error */
644 remote_rcs = lustre_swab_repbuf(request, 1,
645 sizeof(*remote_rcs) * niocount, NULL);
646 if (remote_rcs == NULL) {
647 CERROR("Missing/short RC vector on BRW_WRITE reply\n");
650 if (lustre_msg_swabbed(request->rq_repmsg))
651 for (i = 0; i < niocount; i++)
652 __swab32s(&remote_rcs[i]);
654 for (i = 0; i < niocount; i++) {
655 if (remote_rcs[i] < 0)
656 return(remote_rcs[i]);
658 if (remote_rcs[i] != 0) {
659 CERROR("rc[%d] invalid (%d) req %p\n",
660 i, remote_rcs[i], request);
665 if (request->rq_bulk->bd_nob_transferred != requested_nob) {
666 CERROR("Unexpected # bytes transferred: %d (requested %d)\n",
667 requested_nob, request->rq_bulk->bd_nob_transferred);
674 static inline int can_merge_pages(struct brw_page *p1, struct brw_page *p2)
676 if (p1->flag != p2->flag) {
677 unsigned mask = ~OBD_BRW_FROM_GRANT;
679 /* warn if we try to combine flags that we don't know to be
681 if ((p1->flag & mask) != (p2->flag & mask))
682 CERROR("is it ok to have flags 0x%x and 0x%x in the "
683 "same brw?\n", p1->flag, p2->flag);
687 return (p1->off + p1->count == p2->off);
691 static obd_count cksum_blocks(int nob, obd_count page_count,
692 struct brw_page *pga)
696 LASSERT (page_count > 0);
698 char *ptr = kmap(pga->pg);
699 int psum, off = pga->off & ~PAGE_MASK;
700 int count = pga->count > nob ? nob : pga->count;
703 ost_checksum(&cksum, &psum, ptr + off,
704 count > CHECKSUM_CHUNK ?
705 CHECKSUM_CHUNK : count);
706 LL_CDEBUG_PAGE(D_PAGE, pga->pg, "off %d checksum %x\n",
708 off += CHECKSUM_CHUNK;
709 count -= CHECKSUM_CHUNK;
722 static int osc_brw_prep_request(int cmd, struct obd_import *imp,struct obdo *oa,
723 struct lov_stripe_md *lsm, obd_count page_count,
724 struct brw_page *pga, int *requested_nobp,
725 int *niocountp, struct ptlrpc_request **reqp)
727 struct ptlrpc_request *req;
728 struct ptlrpc_bulk_desc *desc;
729 struct client_obd *cli = &imp->imp_obd->u.cli;
730 struct ost_body *body;
731 struct obd_ioobj *ioobj;
732 struct niobuf_remote *niobuf;
740 opc = ((cmd & OBD_BRW_WRITE) != 0) ? OST_WRITE : OST_READ;
742 for (niocount = i = 1; i < page_count; i++)
743 if (!can_merge_pages(&pga[i - 1], &pga[i]))
746 size[0] = sizeof(*body);
747 size[1] = sizeof(*ioobj);
748 size[2] = niocount * sizeof(*niobuf);
750 req = ptlrpc_prep_req(imp, opc, 3, size, NULL);
754 if (opc == OST_WRITE)
755 desc = ptlrpc_prep_bulk_imp (req, page_count,
756 BULK_GET_SOURCE, OST_BULK_PORTAL);
758 desc = ptlrpc_prep_bulk_imp (req, page_count,
759 BULK_PUT_SINK, OST_BULK_PORTAL);
761 GOTO(out, rc = -ENOMEM);
762 /* NB request now owns desc and will free it when it gets freed */
764 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
765 ioobj = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*ioobj));
766 niobuf = lustre_msg_buf(req->rq_reqmsg, 2, niocount * sizeof(*niobuf));
768 memcpy(&body->oa, oa, sizeof(*oa));
770 obdo_to_ioobj(oa, ioobj);
771 ioobj->ioo_bufcnt = niocount;
773 LASSERT (page_count > 0);
774 for (requested_nob = i = 0; i < page_count; i++, niobuf++) {
775 struct brw_page *pg = &pga[i];
776 struct brw_page *pg_prev = pg - 1;
778 LASSERT(pg->count > 0);
779 LASSERTF((pg->off & ~PAGE_MASK) + pg->count <= PAGE_SIZE,
780 "i: %d pg: %p off: "LPU64", count: %u\n", i, pg,
782 LASSERTF(i == 0 || pg->off > pg_prev->off,
783 "i %d p_c %u pg %p [pri %lu ind %lu] off "LPU64
784 " prev_pg %p [pri %lu ind %lu] off "LPU64"\n",
786 pg->pg, pg->pg->private, pg->pg->index, pg->off,
787 pg_prev->pg, pg_prev->pg->private, pg_prev->pg->index,
790 ptlrpc_prep_bulk_page(desc, pg->pg, pg->off & ~PAGE_MASK,
792 requested_nob += pg->count;
794 if (i > 0 && can_merge_pages(pg_prev, pg)) {
796 niobuf->len += pg->count;
798 niobuf->offset = pg->off;
799 niobuf->len = pg->count;
800 niobuf->flags = pg->flag;
804 LASSERT((void *)(niobuf - niocount) ==
805 lustre_msg_buf(req->rq_reqmsg, 2, niocount * sizeof(*niobuf)));
806 osc_announce_cached(cli, &body->oa, opc == OST_WRITE ? requested_nob:0);
808 /* size[0] still sizeof (*body) */
809 if (opc == OST_WRITE) {
811 body->oa.o_valid |= OBD_MD_FLCKSUM;
812 body->oa.o_cksum = cksum_pages(requested_nob, page_count, pga);
814 /* 1 RC per niobuf */
815 size[1] = sizeof(__u32) * niocount;
816 req->rq_replen = lustre_msg_size(2, size);
818 /* 1 RC for the whole I/O */
819 req->rq_replen = lustre_msg_size(1, size);
822 *niocountp = niocount;
823 *requested_nobp = requested_nob;
828 ptlrpc_req_finished (req);
832 static int osc_brw_fini_request(struct ptlrpc_request *req, struct obdo *oa,
833 int requested_nob, int niocount,
834 obd_count page_count, struct brw_page *pga,
837 struct client_obd *cli = &req->rq_import->imp_obd->u.cli;
838 struct ost_body *body;
844 body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
846 CERROR ("Can't unpack body\n");
850 osc_update_grant(cli, body);
851 memcpy(oa, &body->oa, sizeof(*oa));
853 if (req->rq_reqmsg->opc == OST_WRITE) {
855 CERROR ("Unexpected +ve rc %d\n", rc);
858 LASSERT (req->rq_bulk->bd_nob == requested_nob);
860 RETURN(check_write_rcs(req, requested_nob, niocount,
864 if (rc > requested_nob) {
865 CERROR("Unexpected rc %d (%d requested)\n", rc, requested_nob);
869 if (rc != req->rq_bulk->bd_nob_transferred) {
870 CERROR ("Unexpected rc %d (%d transferred)\n",
871 rc, req->rq_bulk->bd_nob_transferred);
875 if (rc < requested_nob)
876 handle_short_read(rc, page_count, pga);
879 if (oa->o_valid & OBD_MD_FLCKSUM) {
880 const struct ptlrpc_peer *peer =
881 &req->rq_import->imp_connection->c_peer;
882 static int cksum_counter;
883 obd_count server_cksum = oa->o_cksum;
884 obd_count cksum = cksum_pages(rc, page_count, pga);
885 char str[PTL_NALFMT_SIZE];
887 portals_nid2str(peer->peer_ni->pni_number, peer->peer_nid, str);
890 if (server_cksum != cksum) {
891 CERROR("Bad checksum: server %x, client %x, server NID "
892 LPX64" (%s)\n", server_cksum, cksum,
893 peer->peer_nid, str);
896 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
897 CWARN("Checksum %u from "LPX64" (%s) OK: %x\n",
898 cksum_counter, peer->peer_nid, str, cksum);
900 CDEBUG(D_PAGE, "checksum %x\n", cksum);
902 static int cksum_missed;
905 if ((cksum_missed & (-cksum_missed)) == cksum_missed)
906 CERROR("Request checksum %u from "LPX64", no reply\n",
908 req->rq_import->imp_connection->c_peer.peer_nid);
914 static int osc_brw_internal(int cmd, struct obd_export *exp,struct obdo *oa,
915 struct lov_stripe_md *lsm,
916 obd_count page_count, struct brw_page *pga)
920 struct ptlrpc_request *request;
925 rc = osc_brw_prep_request(cmd, class_exp2cliimp(exp), oa, lsm,
926 page_count, pga, &requested_nob, &niocount,
931 rc = ptlrpc_queue_wait(request);
933 if (rc == -ETIMEDOUT && request->rq_resend) {
934 DEBUG_REQ(D_HA, request, "BULK TIMEOUT");
935 ptlrpc_req_finished(request);
939 rc = osc_brw_fini_request(request, oa, requested_nob, niocount,
940 page_count, pga, rc);
942 ptlrpc_req_finished(request);
946 static int brw_interpret(struct ptlrpc_request *request,
947 struct osc_brw_async_args *aa, int rc)
949 struct obdo *oa = aa->aa_oa;
950 int requested_nob = aa->aa_requested_nob;
951 int niocount = aa->aa_nio_count;
952 obd_count page_count = aa->aa_page_count;
953 struct brw_page *pga = aa->aa_pga;
956 rc = osc_brw_fini_request(request, oa, requested_nob, niocount,
957 page_count, pga, rc);
961 static int async_internal(int cmd, struct obd_export *exp, struct obdo *oa,
962 struct lov_stripe_md *lsm, obd_count page_count,
963 struct brw_page *pga, struct ptlrpc_request_set *set)
965 struct ptlrpc_request *request;
968 struct osc_brw_async_args *aa;
972 rc = osc_brw_prep_request(cmd, class_exp2cliimp(exp), oa, lsm,
973 page_count, pga, &requested_nob, &nio_count,
977 LASSERT(sizeof(*aa) <= sizeof(request->rq_async_args));
978 aa = (struct osc_brw_async_args *)&request->rq_async_args;
980 aa->aa_requested_nob = requested_nob;
981 aa->aa_nio_count = nio_count;
982 aa->aa_page_count = page_count;
985 request->rq_interpret_reply = brw_interpret;
986 ptlrpc_set_add_req(set, request);
992 #define min_t(type,x,y) \
993 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
997 * ugh, we want disk allocation on the target to happen in offset order. we'll
998 * follow sedgewicks advice and stick to the dead simple shellsort -- it'll do
999 * fine for our small page arrays and doesn't require allocation. its an
1000 * insertion sort that swaps elements that are strides apart, shrinking the
1001 * stride down until its '1' and the array is sorted.
1003 static void sort_brw_pages(struct brw_page *array, int num)
1006 struct brw_page tmp;
1010 for (stride = 1; stride < num ; stride = (stride * 3) + 1)
1015 for (i = stride ; i < num ; i++) {
1018 while (j >= stride && array[j - stride].off > tmp.off) {
1019 array[j] = array[j - stride];
1024 } while (stride > 1);
1027 /* make sure we the regions we're passing to elan don't violate its '4
1028 * fragments' constraint. portal headers are a fragment, all full
1029 * PAGE_SIZE long pages count as 1 fragment, and each partial page
1030 * counts as a fragment. I think. see bug 934. */
1031 static obd_count check_elan_limit(struct brw_page *pg, obd_count pages)
1034 int saw_whole_frag = 0;
1037 for (i = 0 ; frags_left && i < pages ; pg++, i++) {
1038 if (pg->count == PAGE_SIZE) {
1039 if (!saw_whole_frag) {
1050 static int osc_brw(int cmd, struct obd_export *exp, struct obdo *oa,
1051 struct lov_stripe_md *md, obd_count page_count,
1052 struct brw_page *pga, struct obd_trans_info *oti)
1056 if (cmd == OBD_BRW_CHECK) {
1057 /* The caller just wants to know if there's a chance that this
1058 * I/O can succeed */
1059 struct obd_import *imp = class_exp2cliimp(exp);
1061 if (imp == NULL || imp->imp_invalid)
1066 while (page_count) {
1067 obd_count pages_per_brw;
1070 if (page_count > PTLRPC_MAX_BRW_PAGES)
1071 pages_per_brw = PTLRPC_MAX_BRW_PAGES;
1073 pages_per_brw = page_count;
1075 sort_brw_pages(pga, pages_per_brw);
1076 pages_per_brw = check_elan_limit(pga, pages_per_brw);
1078 rc = osc_brw_internal(cmd, exp, oa, md, pages_per_brw, pga);
1083 page_count -= pages_per_brw;
1084 pga += pages_per_brw;
1089 static int osc_brw_async(int cmd, struct obd_export *exp, struct obdo *oa,
1090 struct lov_stripe_md *md, obd_count page_count,
1091 struct brw_page *pga, struct ptlrpc_request_set *set,
1092 struct obd_trans_info *oti)
1096 if (cmd == OBD_BRW_CHECK) {
1097 /* The caller just wants to know if there's a chance that this
1098 * I/O can succeed */
1099 struct obd_import *imp = class_exp2cliimp(exp);
1101 if (imp == NULL || imp->imp_invalid)
1106 while (page_count) {
1107 obd_count pages_per_brw;
1110 if (page_count > PTLRPC_MAX_BRW_PAGES)
1111 pages_per_brw = PTLRPC_MAX_BRW_PAGES;
1113 pages_per_brw = page_count;
1115 sort_brw_pages(pga, pages_per_brw);
1116 pages_per_brw = check_elan_limit(pga, pages_per_brw);
1118 rc = async_internal(cmd, exp, oa, md, pages_per_brw, pga, set);
1123 page_count -= pages_per_brw;
1124 pga += pages_per_brw;
1129 static void osc_check_rpcs(struct client_obd *cli);
1130 static void osc_exit_cache(struct client_obd *cli, struct osc_async_page *oap,
1132 static void loi_list_maint(struct client_obd *cli, struct lov_oinfo *loi);
1133 static void lop_update_pending(struct client_obd *cli,
1134 struct loi_oap_pages *lop, int cmd, int delta);
1136 /* this is called when a sync waiter receives an interruption. Its job is to
1137 * get the caller woken as soon as possible. If its page hasn't been put in an
1138 * rpc yet it can dequeue immediately. Otherwise it has to mark the rpc as
1139 * desiring interruption which will forcefully complete the rpc once the rpc
1141 static void osc_occ_interrupted(struct oig_callback_context *occ)
1143 struct osc_async_page *oap;
1144 struct loi_oap_pages *lop;
1145 struct lov_oinfo *loi;
1148 /* XXX member_of() */
1149 oap = list_entry(occ, struct osc_async_page, oap_occ);
1151 spin_lock(&oap->oap_cli->cl_loi_list_lock);
1153 oap->oap_interrupted = 1;
1155 /* ok, it's been put in an rpc. */
1156 if (oap->oap_request != NULL) {
1157 ptlrpc_mark_interrupted(oap->oap_request);
1158 ptlrpcd_wake(oap->oap_request);
1162 /* we don't get interruption callbacks until osc_trigger_sync_io()
1163 * has been called and put the sync oaps in the pending/urgent lists.*/
1164 if (!list_empty(&oap->oap_pending_item)) {
1165 list_del_init(&oap->oap_pending_item);
1166 if (oap->oap_async_flags & ASYNC_URGENT)
1167 list_del_init(&oap->oap_urgent_item);
1170 lop = (oap->oap_cmd == OBD_BRW_WRITE) ?
1171 &loi->loi_write_lop : &loi->loi_read_lop;
1172 lop_update_pending(oap->oap_cli, lop, oap->oap_cmd, -1);
1173 loi_list_maint(oap->oap_cli, oap->oap_loi);
1175 oig_complete_one(oap->oap_oig, &oap->oap_occ, 0);
1176 oap->oap_oig = NULL;
1180 spin_unlock(&oap->oap_cli->cl_loi_list_lock);
1183 /* this must be called holding the loi list lock to give coverage to exit_cache,
1184 * async_flag maintenance, and oap_request */
1185 static void osc_ap_completion(struct client_obd *cli, struct obdo *oa,
1186 struct osc_async_page *oap, int sent, int rc)
1188 osc_exit_cache(cli, oap, sent);
1189 oap->oap_async_flags = 0;
1190 oap->oap_interrupted = 0;
1192 if (oap->oap_request != NULL) {
1193 ptlrpc_req_finished(oap->oap_request);
1194 oap->oap_request = NULL;
1197 if (rc == 0 && oa != NULL) {
1198 if (oa->o_valid & OBD_MD_FLBLOCKS)
1199 oap->oap_loi->loi_blocks = oa->o_blocks;
1200 if (oa->o_valid & OBD_MD_FLMTIME)
1201 oap->oap_loi->loi_mtime = oa->o_mtime;
1205 oig_complete_one(oap->oap_oig, &oap->oap_occ, rc);
1206 oap->oap_oig = NULL;
1211 oap->oap_caller_ops->ap_completion(oap->oap_caller_data, oap->oap_cmd,
1215 static int brw_interpret_oap(struct ptlrpc_request *request,
1216 struct osc_brw_async_args *aa, int rc)
1218 struct osc_async_page *oap;
1219 struct client_obd *cli;
1220 struct list_head *pos, *n;
1224 rc = osc_brw_fini_request(request, aa->aa_oa, aa->aa_requested_nob,
1225 aa->aa_nio_count, aa->aa_page_count,
1228 CDEBUG(D_INODE, "request %p aa %p rc %d\n", request, aa, rc);
1231 /* in failout recovery we ignore writeback failure and want
1232 * to just tell llite to unlock the page and continue */
1233 if (request->rq_reqmsg->opc == OST_WRITE &&
1234 (cli->cl_import == NULL || cli->cl_import->imp_invalid)) {
1235 CDEBUG(D_INODE, "flipping to rc 0 imp %p inv %d\n",
1237 cli->cl_import ? cli->cl_import->imp_invalid : -1);
1241 spin_lock(&cli->cl_loi_list_lock);
1243 /* We need to decrement before osc_ap_completion->osc_wake_cache_waiters
1244 * is called so we know whether to go to sync BRWs or wait for more
1245 * RPCs to complete */
1246 if (request->rq_reqmsg->opc == OST_WRITE)
1247 cli->cl_w_in_flight--;
1249 cli->cl_r_in_flight--;
1251 /* the caller may re-use the oap after the completion call so
1252 * we need to clean it up a little */
1253 list_for_each_safe(pos, n, &aa->aa_oaps) {
1254 oap = list_entry(pos, struct osc_async_page, oap_rpc_item);
1256 //CDEBUG(D_INODE, "page %p index %lu oap %p\n",
1257 //oap->oap_page, oap->oap_page->index, oap);
1259 list_del_init(&oap->oap_rpc_item);
1260 osc_ap_completion(cli, aa->aa_oa, oap, 1, rc);
1263 osc_wake_cache_waiters(cli);
1264 osc_check_rpcs(cli);
1266 spin_unlock(&cli->cl_loi_list_lock);
1268 obdo_free(aa->aa_oa);
1269 OBD_FREE(aa->aa_pga, aa->aa_page_count * sizeof(struct brw_page));
1274 static struct ptlrpc_request *osc_build_req(struct client_obd *cli,
1275 struct list_head *rpc_list,
1276 int page_count, int cmd)
1278 struct ptlrpc_request *req;
1279 struct brw_page *pga = NULL;
1280 int requested_nob, nio_count;
1281 struct osc_brw_async_args *aa;
1282 struct obdo *oa = NULL;
1283 struct obd_async_page_ops *ops = NULL;
1284 void *caller_data = NULL;
1285 struct list_head *pos;
1288 LASSERT(!list_empty(rpc_list));
1290 OBD_ALLOC(pga, sizeof(*pga) * page_count);
1292 RETURN(ERR_PTR(-ENOMEM));
1296 GOTO(out, req = ERR_PTR(-ENOMEM));
1299 list_for_each(pos, rpc_list) {
1300 struct osc_async_page *oap;
1302 oap = list_entry(pos, struct osc_async_page, oap_rpc_item);
1304 ops = oap->oap_caller_ops;
1305 caller_data = oap->oap_caller_data;
1307 pga[i].off = oap->oap_obj_off + oap->oap_page_off;
1308 pga[i].pg = oap->oap_page;
1309 pga[i].count = oap->oap_count;
1310 pga[i].flag = oap->oap_brw_flags;
1311 CDEBUG(0, "put page %p index %lu oap %p flg %x to pga\n",
1312 pga[i].pg, oap->oap_page->index, oap, pga[i].flag);
1316 /* always get the data for the obdo for the rpc */
1317 LASSERT(ops != NULL);
1318 ops->ap_fill_obdo(caller_data, cmd, oa);
1320 sort_brw_pages(pga, page_count);
1321 rc = osc_brw_prep_request(cmd, cli->cl_import, oa, NULL, page_count,
1322 pga, &requested_nob, &nio_count, &req);
1324 CERROR("prep_req failed: %d\n", rc);
1325 GOTO(out, req = ERR_PTR(rc));
1328 LASSERT(sizeof(*aa) <= sizeof(req->rq_async_args));
1329 aa = (struct osc_brw_async_args *)&req->rq_async_args;
1331 aa->aa_requested_nob = requested_nob;
1332 aa->aa_nio_count = nio_count;
1333 aa->aa_page_count = page_count;
1342 OBD_FREE(pga, sizeof(*pga) * page_count);
1347 static void lop_update_pending(struct client_obd *cli,
1348 struct loi_oap_pages *lop, int cmd, int delta)
1350 lop->lop_num_pending += delta;
1351 if (cmd == OBD_BRW_WRITE)
1352 cli->cl_pending_w_pages += delta;
1354 cli->cl_pending_r_pages += delta;
1357 /* the loi lock is held across this function but it's allowed to release
1358 * and reacquire it during its work */
1359 static int osc_send_oap_rpc(struct client_obd *cli, struct lov_oinfo *loi,
1360 int cmd, struct loi_oap_pages *lop)
1362 struct ptlrpc_request *request;
1363 obd_count page_count = 0;
1364 struct list_head *tmp, *pos;
1365 struct osc_async_page *oap = NULL;
1366 struct osc_brw_async_args *aa;
1367 struct obd_async_page_ops *ops;
1368 LIST_HEAD(rpc_list);
1371 /* first we find the pages we're allowed to work with */
1372 list_for_each_safe(pos, tmp, &lop->lop_pending) {
1373 oap = list_entry(pos, struct osc_async_page, oap_pending_item);
1374 ops = oap->oap_caller_ops;
1376 LASSERT(oap->oap_magic == OAP_MAGIC);
1378 /* in llite being 'ready' equates to the page being locked
1379 * until completion unlocks it. commit_write submits a page
1380 * as not ready because its unlock will happen unconditionally
1381 * as the call returns. if we race with commit_write giving
1382 * us that page we dont' want to create a hole in the page
1383 * stream, so we stop and leave the rpc to be fired by
1384 * another dirtier or kupdated interval (the not ready page
1385 * will still be on the dirty list). we could call in
1386 * at the end of ll_file_write to process the queue again. */
1387 if (!(oap->oap_async_flags & ASYNC_READY)) {
1388 int rc = ops->ap_make_ready(oap->oap_caller_data, cmd);
1390 CDEBUG(D_INODE, "oap %p page %p returned %d "
1391 "instead of ready\n", oap,
1395 /* llite is telling us that the page is still
1396 * in commit_write and that we should try
1397 * and put it in an rpc again later. we
1398 * break out of the loop so we don't create
1399 * a hole in the sequence of pages in the rpc
1404 /* the io isn't needed.. tell the checks
1405 * below to complete the rpc with EINTR */
1406 oap->oap_async_flags |= ASYNC_COUNT_STABLE;
1407 oap->oap_count = -EINTR;
1410 oap->oap_async_flags |= ASYNC_READY;
1413 LASSERTF(0, "oap %p page %p returned %d "
1414 "from make_ready\n", oap,
1422 /* take the page out of our book-keeping */
1423 list_del_init(&oap->oap_pending_item);
1424 lop_update_pending(cli, lop, cmd, -1);
1425 list_del_init(&oap->oap_urgent_item);
1427 /* ask the caller for the size of the io as the rpc leaves. */
1428 if (!(oap->oap_async_flags & ASYNC_COUNT_STABLE))
1430 ops->ap_refresh_count(oap->oap_caller_data,cmd);
1431 if (oap->oap_count <= 0) {
1432 CDEBUG(D_CACHE, "oap %p count %d, completing\n", oap,
1434 osc_ap_completion(cli, NULL, oap, 0, oap->oap_count);
1438 /* now put the page back in our accounting */
1439 list_add_tail(&oap->oap_rpc_item, &rpc_list);
1440 if (++page_count >= cli->cl_max_pages_per_rpc)
1444 osc_wake_cache_waiters(cli);
1446 if (page_count == 0)
1449 loi_list_maint(cli, loi);
1450 spin_unlock(&cli->cl_loi_list_lock);
1452 request = osc_build_req(cli, &rpc_list, page_count, cmd);
1453 if (IS_ERR(request)) {
1454 /* this should happen rarely and is pretty bad, it makes the
1455 * pending list not follow the dirty order */
1456 spin_lock(&cli->cl_loi_list_lock);
1457 list_for_each_safe(pos, tmp, &rpc_list) {
1458 oap = list_entry(pos, struct osc_async_page,
1460 list_del_init(&oap->oap_rpc_item);
1462 /* queued sync pages can be torn down while the pages
1463 * were between the pending list and the rpc */
1464 if (oap->oap_interrupted) {
1465 CDEBUG(D_INODE, "oap %p interrupted\n", oap);
1466 osc_ap_completion(cli, NULL, oap, 0,
1471 /* put the page back in the loi/lop lists */
1472 list_add_tail(&oap->oap_pending_item,
1474 lop_update_pending(cli, lop, cmd, 1);
1475 if (oap->oap_async_flags & ASYNC_URGENT)
1476 list_add(&oap->oap_urgent_item,
1479 loi_list_maint(cli, loi);
1480 RETURN(PTR_ERR(request));
1483 LASSERT(sizeof(*aa) <= sizeof(request->rq_async_args));
1484 aa = (struct osc_brw_async_args *)&request->rq_async_args;
1485 INIT_LIST_HEAD(&aa->aa_oaps);
1486 list_splice(&rpc_list, &aa->aa_oaps);
1487 INIT_LIST_HEAD(&rpc_list);
1490 if (cmd == OBD_BRW_READ) {
1491 lprocfs_oh_tally_log2(&cli->cl_read_page_hist, page_count);
1492 lprocfs_oh_tally(&cli->cl_read_rpc_hist, cli->cl_r_in_flight);
1494 lprocfs_oh_tally_log2(&cli->cl_write_page_hist, page_count);
1495 lprocfs_oh_tally(&cli->cl_write_rpc_hist,
1496 cli->cl_w_in_flight);
1500 spin_lock(&cli->cl_loi_list_lock);
1502 if (cmd == OBD_BRW_READ)
1503 cli->cl_r_in_flight++;
1505 cli->cl_w_in_flight++;
1506 /* queued sync pages can be torn down while the pages
1507 * were between the pending list and the rpc */
1508 list_for_each(pos, &aa->aa_oaps) {
1509 oap = list_entry(pos, struct osc_async_page, oap_rpc_item);
1510 if (oap->oap_interrupted) {
1511 CDEBUG(D_INODE, "oap %p in req %p interrupted\n",
1513 ptlrpc_mark_interrupted(request);
1518 CDEBUG(D_INODE, "req %p: %d pages, aa %p. now %dr/%dw in flight\n",
1519 request, page_count, aa, cli->cl_r_in_flight,
1520 cli->cl_w_in_flight);
1522 oap->oap_request = ptlrpc_request_addref(request);
1523 request->rq_interpret_reply = brw_interpret_oap;
1524 ptlrpcd_add_req(request);
1528 static int lop_makes_rpc(struct client_obd *cli, struct loi_oap_pages *lop,
1534 if (lop->lop_num_pending == 0)
1537 /* if we have an invalid import we want to drain the queued pages
1538 * by forcing them through rpcs that immediately fail and complete
1539 * the pages. recovery relies on this to empty the queued pages
1540 * before canceling the locks and evicting down the llite pages */
1541 if (cli->cl_import == NULL || cli->cl_import->imp_invalid)
1544 /* stream rpcs in queue order as long as as there is an urgent page
1545 * queued. this is our cheap solution for good batching in the case
1546 * where writepage marks some random page in the middle of the file as
1547 * urgent because of, say, memory pressure */
1548 if (!list_empty(&lop->lop_urgent))
1551 /* fire off rpcs when we have 'optimal' rpcs as tuned for the wire. */
1552 optimal = cli->cl_max_pages_per_rpc;
1553 if (cmd == OBD_BRW_WRITE) {
1554 /* trigger a write rpc stream as long as there are dirtiers
1555 * waiting for space. as they're waiting, they're not going to
1556 * create more pages to coallesce with what's waiting.. */
1557 if (!list_empty(&cli->cl_cache_waiters))
1560 /* *2 to avoid triggering rpcs that would want to include pages
1561 * that are being queued but which can't be made ready until
1562 * the queuer finishes with the page. this is a wart for
1563 * llite::commit_write() */
1566 if (lop->lop_num_pending >= optimal)
1572 static void on_list(struct list_head *item, struct list_head *list,
1575 if (list_empty(item) && should_be_on)
1576 list_add_tail(item, list);
1577 else if (!list_empty(item) && !should_be_on)
1578 list_del_init(item);
1581 /* maintain the loi's cli list membership invariants so that osc_send_oap_rpc
1582 * can find pages to build into rpcs quickly */
1583 static void loi_list_maint(struct client_obd *cli, struct lov_oinfo *loi)
1585 on_list(&loi->loi_cli_item, &cli->cl_loi_ready_list,
1586 lop_makes_rpc(cli, &loi->loi_write_lop, OBD_BRW_WRITE) ||
1587 lop_makes_rpc(cli, &loi->loi_read_lop, OBD_BRW_READ));
1589 on_list(&loi->loi_write_item, &cli->cl_loi_write_list,
1590 loi->loi_write_lop.lop_num_pending);
1592 on_list(&loi->loi_read_item, &cli->cl_loi_read_list,
1593 loi->loi_read_lop.lop_num_pending);
1596 #define LOI_DEBUG(LOI, STR, args...) \
1597 CDEBUG(D_INODE, "loi ready %d wr %d:%d rd %d:%d " STR, \
1598 !list_empty(&(LOI)->loi_cli_item), \
1599 (LOI)->loi_write_lop.lop_num_pending, \
1600 !list_empty(&(LOI)->loi_write_lop.lop_urgent), \
1601 (LOI)->loi_read_lop.lop_num_pending, \
1602 !list_empty(&(LOI)->loi_read_lop.lop_urgent), \
1605 struct lov_oinfo *osc_next_loi(struct client_obd *cli)
1608 /* first return all objects which we already know to have
1609 * pages ready to be stuffed into rpcs */
1610 if (!list_empty(&cli->cl_loi_ready_list))
1611 RETURN(list_entry(cli->cl_loi_ready_list.next,
1612 struct lov_oinfo, loi_cli_item));
1614 /* then if we have cache waiters, return all objects with queued
1615 * writes. This is especially important when many small files
1616 * have filled up the cache and not been fired into rpcs because
1617 * they don't pass the nr_pending/object threshhold */
1618 if (!list_empty(&cli->cl_cache_waiters) &&
1619 !list_empty(&cli->cl_loi_write_list))
1620 RETURN(list_entry(cli->cl_loi_write_list.next,
1621 struct lov_oinfo, loi_write_item));
1623 /* then return all queued objects when we have an invalid import
1624 * so that they get flushed */
1625 if (cli->cl_import == NULL || cli->cl_import->imp_invalid) {
1626 if (!list_empty(&cli->cl_loi_write_list))
1627 RETURN(list_entry(cli->cl_loi_write_list.next,
1628 struct lov_oinfo, loi_write_item));
1629 if (!list_empty(&cli->cl_loi_read_list))
1630 RETURN(list_entry(cli->cl_loi_read_list.next,
1631 struct lov_oinfo, loi_read_item));
1636 /* called with the loi list lock held */
1637 static void osc_check_rpcs(struct client_obd *cli)
1639 struct lov_oinfo *loi;
1640 int rc = 0, race_counter = 0;
1643 while ((loi = osc_next_loi(cli)) != NULL) {
1644 LOI_DEBUG(loi, "%lu in flight\n", rpcs_in_flight(cli));
1646 if (rpcs_in_flight(cli) >= cli->cl_max_rpcs_in_flight)
1649 /* attempt some read/write balancing by alternating between
1650 * reads and writes in an object. The makes_rpc checks here
1651 * would be redundant if we were getting read/write work items
1652 * instead of objects. we don't want send_oap_rpc to drain a
1653 * partial read pending queue when we're given this object to
1654 * do io on writes while there are cache waiters */
1655 if (lop_makes_rpc(cli, &loi->loi_write_lop, OBD_BRW_WRITE)) {
1656 rc = osc_send_oap_rpc(cli, loi, OBD_BRW_WRITE,
1657 &loi->loi_write_lop);
1665 if (lop_makes_rpc(cli, &loi->loi_read_lop, OBD_BRW_READ)) {
1666 rc = osc_send_oap_rpc(cli, loi, OBD_BRW_READ,
1667 &loi->loi_read_lop);
1676 /* attempt some inter-object balancing by issueing rpcs
1677 * for each object in turn */
1678 if (!list_empty(&loi->loi_cli_item))
1679 list_del_init(&loi->loi_cli_item);
1680 if (!list_empty(&loi->loi_write_item))
1681 list_del_init(&loi->loi_write_item);
1682 if (!list_empty(&loi->loi_read_item))
1683 list_del_init(&loi->loi_read_item);
1685 loi_list_maint(cli, loi);
1687 /* send_oap_rpc fails with 0 when make_ready tells it to
1688 * back off. llite's make_ready does this when it tries
1689 * to lock a page queued for write that is already locked.
1690 * we want to try sending rpcs from many objects, but we
1691 * don't want to spin failing with 0. */
1692 if (race_counter == 10)
1698 /* we're trying to queue a page in the osc so we're subject to the
1699 * 'cl_dirty_max' limit on the number of pages that can be queued in the osc.
1700 * If the osc's queued pages are already at that limit, then we want to sleep
1701 * until there is space in the osc's queue for us. We also may be waiting for
1702 * write credits from the OST if there are RPCs in flight that may return some
1703 * before we fall back to sync writes.
1705 * We need this know our allocation was granted in the presence of signals */
1706 static int ocw_granted(struct client_obd *cli, struct osc_cache_waiter *ocw)
1710 spin_lock(&cli->cl_loi_list_lock);
1711 rc = list_empty(&ocw->ocw_entry) || rpcs_in_flight(cli) == 0;
1712 spin_unlock(&cli->cl_loi_list_lock);
1716 /* Caller must hold loi_list_lock - we drop/regain it if we need to wait for
1717 * grant or cache space. */
1718 static int osc_enter_cache(struct client_obd *cli, struct lov_oinfo *loi,
1719 struct osc_async_page *oap)
1721 struct osc_cache_waiter ocw;
1722 struct l_wait_info lwi = { 0 };
1724 CDEBUG(D_CACHE, "dirty: %ld dirty_max: %ld dropped: %lu grant: %lu\n",
1725 cli->cl_dirty, cli->cl_dirty_max, cli->cl_lost_grant,
1726 cli->cl_avail_grant);
1728 if (cli->cl_dirty_max < PAGE_SIZE)
1731 /* Hopefully normal case - cache space and write credits available */
1732 if (cli->cl_dirty + PAGE_SIZE <= cli->cl_dirty_max &&
1733 cli->cl_avail_grant >= PAGE_SIZE) {
1734 /* account for ourselves */
1735 osc_consume_write_grant(cli, oap);
1739 /* Make sure that there are write rpcs in flight to wait for. This
1740 * is a little silly as this object may not have any pending but
1741 * other objects sure might. */
1742 if (cli->cl_w_in_flight) {
1743 list_add_tail(&ocw.ocw_entry, &cli->cl_cache_waiters);
1744 init_waitqueue_head(&ocw.ocw_waitq);
1748 loi_list_maint(cli, loi);
1749 osc_check_rpcs(cli);
1750 spin_unlock(&cli->cl_loi_list_lock);
1752 CDEBUG(0, "sleeping for cache space\n");
1753 l_wait_event(ocw.ocw_waitq, ocw_granted(cli, &ocw), &lwi);
1755 spin_lock(&cli->cl_loi_list_lock);
1756 if (!list_empty(&ocw.ocw_entry)) {
1757 list_del(&ocw.ocw_entry);
1766 /* the companion to enter_cache, called when an oap is no longer part of the
1767 * dirty accounting.. so writeback completes or truncate happens before writing
1768 * starts. must be called with the loi lock held. */
1769 static void osc_exit_cache(struct client_obd *cli, struct osc_async_page *oap,
1772 int blocksize = cli->cl_import->imp_obd->obd_osfs.os_bsize ? : 4096;
1775 if (!(oap->oap_brw_flags & OBD_BRW_FROM_GRANT)) {
1780 oap->oap_brw_flags &= ~OBD_BRW_FROM_GRANT;
1781 cli->cl_dirty -= PAGE_SIZE;
1783 cli->cl_lost_grant += PAGE_SIZE;
1784 CDEBUG(D_CACHE, "lost grant: %lu avail grant: %lu dirty: %lu\n",
1785 cli->cl_lost_grant, cli->cl_avail_grant, cli->cl_dirty);
1786 } else if (PAGE_SIZE != blocksize && oap->oap_count != PAGE_SIZE) {
1787 /* For short writes we shouldn't count parts of pages that
1788 * span a whole block on the OST side, or our accounting goes
1789 * wrong. Should match the code in filter_grant_check. */
1790 int offset = (oap->oap_obj_off +oap->oap_page_off) & ~PAGE_MASK;
1791 int count = oap->oap_count + (offset & (blocksize - 1));
1792 int end = (offset + oap->oap_count) & (blocksize - 1);
1794 count += blocksize - end;
1796 cli->cl_lost_grant += PAGE_SIZE - count;
1797 CDEBUG(D_CACHE, "lost %lu grant: %lu avail: %lu dirty: %lu\n",
1798 PAGE_SIZE - count, cli->cl_lost_grant,
1799 cli->cl_avail_grant, cli->cl_dirty);
1805 int osc_prep_async_page(struct obd_export *exp, struct lov_stripe_md *lsm,
1806 struct lov_oinfo *loi, struct page *page,
1807 obd_off offset, struct obd_async_page_ops *ops,
1808 void *data, void **res)
1810 struct osc_async_page *oap;
1813 OBD_ALLOC(oap, sizeof(*oap));
1817 oap->oap_magic = OAP_MAGIC;
1818 oap->oap_cli = &exp->exp_obd->u.cli;
1821 oap->oap_caller_ops = ops;
1822 oap->oap_caller_data = data;
1824 oap->oap_page = page;
1825 oap->oap_obj_off = offset;
1827 INIT_LIST_HEAD(&oap->oap_pending_item);
1828 INIT_LIST_HEAD(&oap->oap_urgent_item);
1829 INIT_LIST_HEAD(&oap->oap_rpc_item);
1831 oap->oap_occ.occ_interrupted = osc_occ_interrupted;
1833 CDEBUG(D_CACHE, "oap %p page %p obj off "LPU64"\n", oap, page, offset);
1838 struct osc_async_page *oap_from_cookie(void *cookie)
1840 struct osc_async_page *oap = cookie;
1841 if (oap->oap_magic != OAP_MAGIC)
1842 return ERR_PTR(-EINVAL);
1846 static int osc_queue_async_io(struct obd_export *exp, struct lov_stripe_md *lsm,
1847 struct lov_oinfo *loi, void *cookie,
1848 int cmd, obd_off off, int count,
1849 obd_flag brw_flags, enum async_flags async_flags)
1851 struct client_obd *cli = &exp->exp_obd->u.cli;
1852 struct osc_async_page *oap;
1853 struct loi_oap_pages *lop;
1857 oap = oap_from_cookie(cookie);
1859 RETURN(PTR_ERR(oap));
1861 if (cli->cl_import == NULL || cli->cl_import->imp_invalid)
1864 if (!list_empty(&oap->oap_pending_item) ||
1865 !list_empty(&oap->oap_urgent_item) ||
1866 !list_empty(&oap->oap_rpc_item))
1870 loi = &lsm->lsm_oinfo[0];
1872 spin_lock(&cli->cl_loi_list_lock);
1875 oap->oap_async_flags = async_flags;
1876 oap->oap_page_off = off;
1877 oap->oap_count = count;
1878 oap->oap_brw_flags = brw_flags;
1880 if (cmd == OBD_BRW_WRITE) {
1881 rc = osc_enter_cache(cli, loi, oap);
1883 spin_unlock(&cli->cl_loi_list_lock);
1886 lop = &loi->loi_write_lop;
1888 lop = &loi->loi_read_lop;
1891 if (oap->oap_async_flags & ASYNC_URGENT)
1892 list_add(&oap->oap_urgent_item, &lop->lop_urgent);
1893 list_add_tail(&oap->oap_pending_item, &lop->lop_pending);
1894 lop_update_pending(cli, lop, cmd, 1);
1896 loi_list_maint(cli, loi);
1898 LOI_DEBUG(loi, "oap %p page %p added for cmd %d\n", oap, oap->oap_page,
1901 osc_check_rpcs(cli);
1902 spin_unlock(&cli->cl_loi_list_lock);
1907 /* aka (~was & now & flag), but this is more clear :) */
1908 #define SETTING(was, now, flag) (!(was & flag) && (now & flag))
1910 static int osc_set_async_flags(struct obd_export *exp,
1911 struct lov_stripe_md *lsm,
1912 struct lov_oinfo *loi, void *cookie,
1913 obd_flag async_flags)
1915 struct client_obd *cli = &exp->exp_obd->u.cli;
1916 struct loi_oap_pages *lop;
1917 struct osc_async_page *oap;
1921 oap = oap_from_cookie(cookie);
1923 RETURN(PTR_ERR(oap));
1925 if (cli->cl_import == NULL || cli->cl_import->imp_invalid)
1929 loi = &lsm->lsm_oinfo[0];
1931 if (oap->oap_cmd == OBD_BRW_WRITE) {
1932 lop = &loi->loi_write_lop;
1934 lop = &loi->loi_read_lop;
1937 spin_lock(&cli->cl_loi_list_lock);
1939 if (list_empty(&oap->oap_pending_item))
1940 GOTO(out, rc = -EINVAL);
1942 if ((oap->oap_async_flags & async_flags) == async_flags)
1945 if (SETTING(oap->oap_async_flags, async_flags, ASYNC_READY))
1946 oap->oap_async_flags |= ASYNC_READY;
1948 if (SETTING(oap->oap_async_flags, async_flags, ASYNC_URGENT)) {
1949 if (list_empty(&oap->oap_rpc_item)) {
1950 list_add(&oap->oap_urgent_item, &lop->lop_urgent);
1951 loi_list_maint(cli, loi);
1955 LOI_DEBUG(loi, "oap %p page %p has flags %x\n", oap, oap->oap_page,
1956 oap->oap_async_flags);
1958 osc_check_rpcs(cli);
1959 spin_unlock(&cli->cl_loi_list_lock);
1963 static int osc_queue_group_io(struct obd_export *exp, struct lov_stripe_md *lsm,
1964 struct lov_oinfo *loi,
1965 struct obd_io_group *oig, void *cookie,
1966 int cmd, obd_off off, int count,
1968 obd_flag async_flags)
1970 struct client_obd *cli = &exp->exp_obd->u.cli;
1971 struct osc_async_page *oap;
1972 struct loi_oap_pages *lop;
1975 oap = oap_from_cookie(cookie);
1977 RETURN(PTR_ERR(oap));
1979 if (cli->cl_import == NULL || cli->cl_import->imp_invalid)
1982 if (!list_empty(&oap->oap_pending_item) ||
1983 !list_empty(&oap->oap_urgent_item) ||
1984 !list_empty(&oap->oap_rpc_item))
1988 loi = &lsm->lsm_oinfo[0];
1990 spin_lock(&cli->cl_loi_list_lock);
1993 oap->oap_page_off = off;
1994 oap->oap_count = count;
1995 oap->oap_brw_flags = brw_flags;
1996 oap->oap_async_flags = async_flags;
1998 if (cmd == OBD_BRW_WRITE)
1999 lop = &loi->loi_write_lop;
2001 lop = &loi->loi_read_lop;
2003 list_add_tail(&oap->oap_pending_item, &lop->lop_pending_group);
2004 if (oap->oap_async_flags & ASYNC_GROUP_SYNC) {
2006 oig_add_one(oig, &oap->oap_occ);
2009 LOI_DEBUG(loi, "oap %p page %p on group pending\n", oap, oap->oap_page);
2011 spin_unlock(&cli->cl_loi_list_lock);
2016 static void osc_group_to_pending(struct client_obd *cli, struct lov_oinfo *loi,
2017 struct loi_oap_pages *lop, int cmd)
2019 struct list_head *pos, *tmp;
2020 struct osc_async_page *oap;
2022 list_for_each_safe(pos, tmp, &lop->lop_pending_group) {
2023 oap = list_entry(pos, struct osc_async_page, oap_pending_item);
2024 list_del(&oap->oap_pending_item);
2025 list_add_tail(&oap->oap_pending_item, &lop->lop_pending);
2026 list_add(&oap->oap_urgent_item, &lop->lop_urgent);
2027 lop_update_pending(cli, lop, cmd, 1);
2029 loi_list_maint(cli, loi);
2032 static int osc_trigger_group_io(struct obd_export *exp,
2033 struct lov_stripe_md *lsm,
2034 struct lov_oinfo *loi,
2035 struct obd_io_group *oig)
2037 struct client_obd *cli = &exp->exp_obd->u.cli;
2041 loi = &lsm->lsm_oinfo[0];
2043 spin_lock(&cli->cl_loi_list_lock);
2045 osc_group_to_pending(cli, loi, &loi->loi_write_lop, OBD_BRW_WRITE);
2046 osc_group_to_pending(cli, loi, &loi->loi_read_lop, OBD_BRW_READ);
2048 osc_check_rpcs(cli);
2049 spin_unlock(&cli->cl_loi_list_lock);
2054 static int osc_teardown_async_page(struct obd_export *exp,
2055 struct lov_stripe_md *lsm,
2056 struct lov_oinfo *loi, void *cookie)
2058 struct client_obd *cli = &exp->exp_obd->u.cli;
2059 struct loi_oap_pages *lop;
2060 struct osc_async_page *oap;
2064 oap = oap_from_cookie(cookie);
2066 RETURN(PTR_ERR(oap));
2069 loi = &lsm->lsm_oinfo[0];
2071 if (oap->oap_cmd == OBD_BRW_WRITE) {
2072 lop = &loi->loi_write_lop;
2074 lop = &loi->loi_read_lop;
2077 spin_lock(&cli->cl_loi_list_lock);
2079 if (!list_empty(&oap->oap_rpc_item))
2080 GOTO(out, rc = -EBUSY);
2082 osc_exit_cache(cli, oap, 0);
2083 osc_wake_cache_waiters(cli);
2085 if (!list_empty(&oap->oap_urgent_item)) {
2086 list_del_init(&oap->oap_urgent_item);
2087 oap->oap_async_flags &= ~ASYNC_URGENT;
2089 if (!list_empty(&oap->oap_pending_item)) {
2090 list_del_init(&oap->oap_pending_item);
2091 lop_update_pending(cli, lop, oap->oap_cmd, -1);
2093 loi_list_maint(cli, loi);
2095 LOI_DEBUG(loi, "oap %p page %p torn down\n", oap, oap->oap_page);
2097 spin_unlock(&cli->cl_loi_list_lock);
2099 OBD_FREE(oap, sizeof(*oap));
2104 /* Note: caller will lock/unlock, and set uptodate on the pages */
2105 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
2106 static int sanosc_brw_read(struct obd_export *exp, struct obdo *oa,
2107 struct lov_stripe_md *lsm, obd_count page_count,
2108 struct brw_page *pga)
2110 struct ptlrpc_request *request = NULL;
2111 struct ost_body *body;
2112 struct niobuf_remote *nioptr;
2113 struct obd_ioobj *iooptr;
2114 int rc, size[3] = {sizeof(*body)}, mapped = 0;
2118 /* XXX does not handle 'new' brw protocol */
2120 size[1] = sizeof(struct obd_ioobj);
2121 size[2] = page_count * sizeof(*nioptr);
2123 request = ptlrpc_prep_req(class_exp2cliimp(exp), OST_SAN_READ, 3,
2128 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof(*body));
2129 iooptr = lustre_msg_buf(request->rq_reqmsg, 1, sizeof(*iooptr));
2130 nioptr = lustre_msg_buf(request->rq_reqmsg, 2,
2131 sizeof(*nioptr) * page_count);
2133 memcpy(&body->oa, oa, sizeof(body->oa));
2135 obdo_to_ioobj(oa, iooptr);
2136 iooptr->ioo_bufcnt = page_count;
2138 for (mapped = 0; mapped < page_count; mapped++, nioptr++) {
2139 LASSERT(PageLocked(pga[mapped].pg));
2140 LASSERT(mapped == 0 || pga[mapped].off > pga[mapped - 1].off);
2142 nioptr->offset = pga[mapped].off;
2143 nioptr->len = pga[mapped].count;
2144 nioptr->flags = pga[mapped].flag;
2147 size[1] = page_count * sizeof(*nioptr);
2148 request->rq_replen = lustre_msg_size(2, size);
2150 rc = ptlrpc_queue_wait(request);
2154 body = lustre_swab_repbuf(request, 0, sizeof(*body),
2155 lustre_swab_ost_body);
2157 CERROR("Can't unpack body\n");
2158 GOTO(out_req, rc = -EPROTO);
2161 memcpy(oa, &body->oa, sizeof(*oa));
2163 swab = lustre_msg_swabbed(request->rq_repmsg);
2164 LASSERT_REPSWAB(request, 1);
2165 nioptr = lustre_msg_buf(request->rq_repmsg, 1, size[1]);
2167 /* nioptr missing or short */
2168 GOTO(out_req, rc = -EPROTO);
2172 for (mapped = 0; mapped < page_count; mapped++, nioptr++) {
2173 struct page *page = pga[mapped].pg;
2174 struct buffer_head *bh;
2178 lustre_swab_niobuf_remote (nioptr);
2180 /* got san device associated */
2181 LASSERT(exp->exp_obd != NULL);
2182 dev = exp->exp_obd->u.cli.cl_sandev;
2185 if (!nioptr->offset) {
2186 CDEBUG(D_PAGE, "hole at ino %lu; index %ld\n",
2187 page->mapping->host->i_ino,
2189 memset(page_address(page), 0, PAGE_SIZE);
2193 if (!page->buffers) {
2194 create_empty_buffers(page, dev, PAGE_SIZE);
2197 clear_bit(BH_New, &bh->b_state);
2198 set_bit(BH_Mapped, &bh->b_state);
2199 bh->b_blocknr = (unsigned long)nioptr->offset;
2201 clear_bit(BH_Uptodate, &bh->b_state);
2203 ll_rw_block(READ, 1, &bh);
2207 /* if buffer already existed, it must be the
2208 * one we mapped before, check it */
2209 LASSERT(!test_bit(BH_New, &bh->b_state));
2210 LASSERT(test_bit(BH_Mapped, &bh->b_state));
2211 LASSERT(bh->b_blocknr == (unsigned long)nioptr->offset);
2213 /* wait it's io completion */
2214 if (test_bit(BH_Lock, &bh->b_state))
2217 if (!test_bit(BH_Uptodate, &bh->b_state))
2218 ll_rw_block(READ, 1, &bh);
2222 /* must do syncronous write here */
2224 if (!buffer_uptodate(bh)) {
2232 ptlrpc_req_finished(request);
2236 static int sanosc_brw_write(struct obd_export *exp, struct obdo *oa,
2237 struct lov_stripe_md *lsm, obd_count page_count,
2238 struct brw_page *pga)
2240 struct ptlrpc_request *request = NULL;
2241 struct ost_body *body;
2242 struct niobuf_remote *nioptr;
2243 struct obd_ioobj *iooptr;
2244 int rc, size[3] = {sizeof(*body)}, mapped = 0;
2248 size[1] = sizeof(struct obd_ioobj);
2249 size[2] = page_count * sizeof(*nioptr);
2251 request = ptlrpc_prep_req(class_exp2cliimp(exp), OST_SAN_WRITE,
2256 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
2257 iooptr = lustre_msg_buf(request->rq_reqmsg, 1, sizeof (*iooptr));
2258 nioptr = lustre_msg_buf(request->rq_reqmsg, 2,
2259 sizeof (*nioptr) * page_count);
2261 memcpy(&body->oa, oa, sizeof(body->oa));
2263 obdo_to_ioobj(oa, iooptr);
2264 iooptr->ioo_bufcnt = page_count;
2267 for (mapped = 0; mapped < page_count; mapped++, nioptr++) {
2268 LASSERT(PageLocked(pga[mapped].pg));
2269 LASSERT(mapped == 0 || pga[mapped].off > pga[mapped - 1].off);
2271 nioptr->offset = pga[mapped].off;
2272 nioptr->len = pga[mapped].count;
2273 nioptr->flags = pga[mapped].flag;
2276 size[1] = page_count * sizeof(*nioptr);
2277 request->rq_replen = lustre_msg_size(2, size);
2279 rc = ptlrpc_queue_wait(request);
2283 swab = lustre_msg_swabbed (request->rq_repmsg);
2284 LASSERT_REPSWAB (request, 1);
2285 nioptr = lustre_msg_buf(request->rq_repmsg, 1, size[1]);
2287 CERROR("absent/short niobuf array\n");
2288 GOTO(out_req, rc = -EPROTO);
2292 for (mapped = 0; mapped < page_count; mapped++, nioptr++) {
2293 struct page *page = pga[mapped].pg;
2294 struct buffer_head *bh;
2298 lustre_swab_niobuf_remote (nioptr);
2300 /* got san device associated */
2301 LASSERT(exp->exp_obd != NULL);
2302 dev = exp->exp_obd->u.cli.cl_sandev;
2304 if (!page->buffers) {
2305 create_empty_buffers(page, dev, PAGE_SIZE);
2308 LASSERT(!test_bit(BH_New, &page->buffers->b_state));
2309 LASSERT(test_bit(BH_Mapped, &page->buffers->b_state));
2310 LASSERT(page->buffers->b_blocknr ==
2311 (unsigned long)nioptr->offset);
2317 /* if buffer locked, wait it's io completion */
2318 if (test_bit(BH_Lock, &bh->b_state))
2321 clear_bit(BH_New, &bh->b_state);
2322 set_bit(BH_Mapped, &bh->b_state);
2324 /* override the block nr */
2325 bh->b_blocknr = (unsigned long)nioptr->offset;
2327 /* we are about to write it, so set it
2329 * page lock should garentee no race condition here */
2330 set_bit(BH_Uptodate, &bh->b_state);
2331 set_bit(BH_Dirty, &bh->b_state);
2333 ll_rw_block(WRITE, 1, &bh);
2335 /* must do syncronous write here */
2337 if (!buffer_uptodate(bh) || test_bit(BH_Dirty, &bh->b_state)) {
2345 ptlrpc_req_finished(request);
2349 static int sanosc_brw(int cmd, struct obd_export *exp, struct obdo *oa,
2350 struct lov_stripe_md *lsm, obd_count page_count,
2351 struct brw_page *pga, struct obd_trans_info *oti)
2355 while (page_count) {
2356 obd_count pages_per_brw;
2359 if (page_count > PTLRPC_MAX_BRW_PAGES)
2360 pages_per_brw = PTLRPC_MAX_BRW_PAGES;
2362 pages_per_brw = page_count;
2364 if (cmd & OBD_BRW_WRITE)
2365 rc = sanosc_brw_write(exp, oa, lsm, pages_per_brw,pga);
2367 rc = sanosc_brw_read(exp, oa, lsm, pages_per_brw, pga);
2372 page_count -= pages_per_brw;
2373 pga += pages_per_brw;
2380 static void osc_set_data_with_check(struct lustre_handle *lockh, void *data)
2382 struct ldlm_lock *lock = ldlm_handle2lock(lockh);
2385 CERROR("lockh %p, data %p - client evicted?\n", lockh, data);
2388 l_lock(&lock->l_resource->lr_namespace->ns_lock);
2390 if (lock->l_ast_data && lock->l_ast_data != data) {
2391 struct inode *new_inode = data;
2392 struct inode *old_inode = lock->l_ast_data;
2393 if (!(old_inode->i_state & I_FREEING))
2394 LDLM_ERROR(lock, "inconsistent l_ast_data found");
2395 LASSERTF(old_inode->i_state & I_FREEING,
2396 "Found existing inode %p/%lu/%u state %lu in lock: "
2397 "setting data to %p/%lu/%u\n", old_inode,
2398 old_inode->i_ino, old_inode->i_generation,
2400 new_inode, new_inode->i_ino, new_inode->i_generation);
2403 lock->l_ast_data = data;
2404 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
2405 LDLM_LOCK_PUT(lock);
2408 static int osc_change_cbdata(struct obd_export *exp, struct lov_stripe_md *lsm,
2409 ldlm_iterator_t replace, void *data)
2411 struct ldlm_res_id res_id = { .name = {lsm->lsm_object_id} };
2412 struct obd_device *obd = class_exp2obd(exp);
2414 ldlm_change_cbdata(obd->obd_namespace, &res_id, replace, data);
2418 static int osc_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm,
2419 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
2420 int *flags, void *bl_cb, void *cp_cb, void *gl_cb,
2421 void *data, __u32 lvb_len, void *lvb_swabber,
2422 struct lustre_handle *lockh)
2424 struct ldlm_res_id res_id = { .name = {lsm->lsm_object_id} };
2425 struct obd_device *obd = exp->exp_obd;
2427 struct ldlm_reply *rep;
2428 struct ptlrpc_request *req = NULL;
2432 /* Filesystem lock extents are extended to page boundaries so that
2433 * dealing with the page cache is a little smoother. */
2434 policy->l_extent.start -= policy->l_extent.start & ~PAGE_MASK;
2435 policy->l_extent.end |= ~PAGE_MASK;
2437 if (lsm->lsm_oinfo->loi_kms_valid == 0)
2440 /* Next, search for already existing extent locks that will cover us */
2441 rc = ldlm_lock_match(obd->obd_namespace, 0, &res_id, type, policy, mode,
2444 osc_set_data_with_check(lockh, data);
2445 if (*flags & LDLM_FL_HAS_INTENT) {
2446 /* I would like to be able to ASSERT here that rss <=
2447 * kms, but I can't, for reasons which are explained in
2450 /* We already have a lock, and it's referenced */
2454 /* If we're trying to read, we also search for an existing PW lock. The
2455 * VFS and page cache already protect us locally, so lots of readers/
2456 * writers can share a single PW lock.
2458 * There are problems with conversion deadlocks, so instead of
2459 * converting a read lock to a write lock, we'll just enqueue a new
2462 * At some point we should cancel the read lock instead of making them
2463 * send us a blocking callback, but there are problems with canceling
2464 * locks out from other users right now, too. */
2466 if (mode == LCK_PR) {
2467 rc = ldlm_lock_match(obd->obd_namespace, 0, &res_id, type,
2468 policy, LCK_PW, lockh);
2470 /* FIXME: This is not incredibly elegant, but it might
2471 * be more elegant than adding another parameter to
2472 * lock_match. I want a second opinion. */
2473 ldlm_lock_addref(lockh, LCK_PR);
2474 ldlm_lock_decref(lockh, LCK_PW);
2475 osc_set_data_with_check(lockh, data);
2481 if (*flags & LDLM_FL_HAS_INTENT) {
2482 int size[2] = {sizeof(struct ldlm_request), sizeof(lvb)};
2484 req = ptlrpc_prep_req(class_exp2cliimp(exp), LDLM_ENQUEUE, 1,
2489 size[0] = sizeof(*rep);
2490 req->rq_replen = lustre_msg_size(2, size);
2493 rc = ldlm_cli_enqueue(exp, req, obd->obd_namespace, res_id, type,
2494 policy, mode, flags, bl_cb, cp_cb, gl_cb, data,
2495 &lvb, sizeof(lvb), lustre_swab_ost_lvb, lockh);
2498 if (rc == ELDLM_LOCK_ABORTED) {
2499 /* swabbed by ldlm_cli_enqueue() */
2500 LASSERT_REPSWABBED(req, 0);
2501 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep));
2502 LASSERT(rep != NULL);
2503 if (rep->lock_policy_res1)
2504 rc = rep->lock_policy_res1;
2506 ptlrpc_req_finished(req);
2509 if ((*flags & LDLM_FL_HAS_INTENT && rc == ELDLM_LOCK_ABORTED) || !rc) {
2510 CDEBUG(D_INODE,"got kms "LPU64" blocks "LPU64" mtime "LPU64"\n",
2511 lvb.lvb_size, lvb.lvb_blocks, lvb.lvb_mtime);
2512 lsm->lsm_oinfo->loi_rss = lvb.lvb_size;
2513 lsm->lsm_oinfo->loi_mtime = lvb.lvb_mtime;
2514 lsm->lsm_oinfo->loi_blocks = lvb.lvb_blocks;
2520 static int osc_match(struct obd_export *exp, struct lov_stripe_md *lsm,
2521 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
2522 int *flags, void *data, struct lustre_handle *lockh)
2524 struct ldlm_res_id res_id = { .name = {lsm->lsm_object_id} };
2525 struct obd_device *obd = exp->exp_obd;
2529 OBD_FAIL_RETURN(OBD_FAIL_OSC_MATCH, -EIO);
2531 /* Filesystem lock extents are extended to page boundaries so that
2532 * dealing with the page cache is a little smoother */
2533 policy->l_extent.start -= policy->l_extent.start & ~PAGE_MASK;
2534 policy->l_extent.end |= ~PAGE_MASK;
2536 /* Next, search for already existing extent locks that will cover us */
2537 rc = ldlm_lock_match(obd->obd_namespace, *flags, &res_id, type,
2538 policy, mode, lockh);
2540 //if (!(*flags & LDLM_FL_TEST_LOCK))
2541 osc_set_data_with_check(lockh, data);
2544 /* If we're trying to read, we also search for an existing PW lock. The
2545 * VFS and page cache already protect us locally, so lots of readers/
2546 * writers can share a single PW lock. */
2547 if (mode == LCK_PR) {
2548 rc = ldlm_lock_match(obd->obd_namespace, *flags, &res_id, type,
2549 policy, LCK_PW, lockh);
2550 if (rc == 1 && !(*flags & LDLM_FL_TEST_LOCK)) {
2551 /* FIXME: This is not incredibly elegant, but it might
2552 * be more elegant than adding another parameter to
2553 * lock_match. I want a second opinion. */
2554 osc_set_data_with_check(lockh, data);
2555 ldlm_lock_addref(lockh, LCK_PR);
2556 ldlm_lock_decref(lockh, LCK_PW);
2562 static int osc_cancel(struct obd_export *exp, struct lov_stripe_md *md,
2563 __u32 mode, struct lustre_handle *lockh)
2567 ldlm_lock_decref(lockh, mode);
2572 static int osc_cancel_unused(struct obd_export *exp,
2573 struct lov_stripe_md *lsm, int flags, void *opaque)
2575 struct obd_device *obd = class_exp2obd(exp);
2576 struct ldlm_res_id res_id = { .name = {lsm->lsm_object_id} };
2578 return ldlm_cli_cancel_unused(obd->obd_namespace, &res_id, flags,
2582 static int osc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2583 unsigned long max_age)
2585 struct obd_statfs *msfs;
2586 struct ptlrpc_request *request;
2587 int rc, size = sizeof(*osfs);
2590 /* We could possibly pass max_age in the request (as an absolute
2591 * timestamp or a "seconds.usec ago") so the target can avoid doing
2592 * extra calls into the filesystem if that isn't necessary (e.g.
2593 * during mount that would help a bit). Having relative timestamps
2594 * is not so great if request processing is slow, while absolute
2595 * timestamps are not ideal because they need time synchronization. */
2596 request = ptlrpc_prep_req(obd->u.cli.cl_import, OST_STATFS,0,NULL,NULL);
2600 request->rq_replen = lustre_msg_size(1, &size);
2601 request->rq_request_portal = OST_CREATE_PORTAL; //XXX FIXME bug 249
2603 rc = ptlrpc_queue_wait(request);
2607 msfs = lustre_swab_repbuf(request, 0, sizeof(*msfs),
2608 lustre_swab_obd_statfs);
2610 CERROR("Can't unpack obd_statfs\n");
2611 GOTO(out, rc = -EPROTO);
2614 memcpy(osfs, msfs, sizeof(*osfs));
2618 ptlrpc_req_finished(request);
2622 /* Retrieve object striping information.
2624 * @lmmu is a pointer to an in-core struct with lmm_ost_count indicating
2625 * the maximum number of OST indices which will fit in the user buffer.
2626 * lmm_magic must be LOV_MAGIC (we only use 1 slot here).
2628 static int osc_getstripe(struct lov_stripe_md *lsm, struct lov_user_md *lump)
2630 struct lov_user_md lum, *lumk;
2637 rc = copy_from_user(&lum, lump, sizeof(lum));
2641 if (lum.lmm_magic != LOV_USER_MAGIC)
2644 if (lum.lmm_stripe_count > 0) {
2645 lum_size = sizeof(lum) + sizeof(lum.lmm_objects[0]);
2646 OBD_ALLOC(lumk, lum_size);
2650 lumk->lmm_objects[0].l_object_id = lsm->lsm_object_id;
2652 lum_size = sizeof(lum);
2656 lumk->lmm_object_id = lsm->lsm_object_id;
2657 lumk->lmm_stripe_count = 1;
2659 if (copy_to_user(lump, lumk, lum_size))
2663 OBD_FREE(lumk, lum_size);
2668 static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2669 void *karg, void *uarg)
2671 struct obd_device *obd = exp->exp_obd;
2672 struct obd_ioctl_data *data = karg;
2676 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
2679 if (!try_module_get(THIS_MODULE)) {
2680 CERROR("Can't get module. Is it alive?");
2685 case OBD_IOC_LOV_GET_CONFIG: {
2687 struct lov_desc *desc;
2688 struct obd_uuid uuid;
2692 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
2693 GOTO(out, err = -EINVAL);
2695 data = (struct obd_ioctl_data *)buf;
2697 if (sizeof(*desc) > data->ioc_inllen1) {
2699 GOTO(out, err = -EINVAL);
2702 if (data->ioc_inllen2 < sizeof(uuid)) {
2704 GOTO(out, err = -EINVAL);
2707 desc = (struct lov_desc *)data->ioc_inlbuf1;
2708 desc->ld_tgt_count = 1;
2709 desc->ld_active_tgt_count = 1;
2710 desc->ld_default_stripe_count = 1;
2711 desc->ld_default_stripe_size = 0;
2712 desc->ld_default_stripe_offset = 0;
2713 desc->ld_pattern = 0;
2714 memcpy(&desc->ld_uuid, &obd->obd_uuid, sizeof(uuid));
2716 memcpy(data->ioc_inlbuf2, &obd->obd_uuid, sizeof(uuid));
2718 err = copy_to_user((void *)uarg, buf, len);
2721 obd_ioctl_freedata(buf, len);
2724 case LL_IOC_LOV_SETSTRIPE:
2725 err = obd_alloc_memmd(exp, karg);
2729 case LL_IOC_LOV_GETSTRIPE:
2730 err = osc_getstripe(karg, uarg);
2732 case OBD_IOC_CLIENT_RECOVER:
2733 err = ptlrpc_recover_import(obd->u.cli.cl_import,
2738 case IOC_OSC_SET_ACTIVE:
2739 err = ptlrpc_set_import_active(obd->u.cli.cl_import,
2743 CDEBUG(D_INODE, "unrecognised ioctl %#x by %s\n", cmd, current->comm);
2744 GOTO(out, err = -ENOTTY);
2747 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
2750 module_put(THIS_MODULE);
2755 static int osc_get_info(struct obd_export *exp, obd_count keylen,
2756 void *key, __u32 *vallen, void *val)
2759 if (!vallen || !val)
2762 if (keylen > strlen("lock_to_stripe") &&
2763 strcmp(key, "lock_to_stripe") == 0) {
2764 __u32 *stripe = val;
2765 *vallen = sizeof(*stripe);
2768 } else if (keylen >= strlen("last_id") && strcmp(key, "last_id") == 0) {
2769 struct ptlrpc_request *req;
2771 char *bufs[1] = {key};
2773 req = ptlrpc_prep_req(class_exp2cliimp(exp), OST_GET_INFO, 1,
2778 req->rq_replen = lustre_msg_size(1, vallen);
2779 rc = ptlrpc_queue_wait(req);
2783 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
2784 lustre_swab_ost_last_id);
2785 if (reply == NULL) {
2786 CERROR("Can't unpack OST last ID\n");
2787 GOTO(out, rc = -EPROTO);
2789 *((obd_id *)val) = *reply;
2791 ptlrpc_req_finished(req);
2797 static int osc_set_info(struct obd_export *exp, obd_count keylen,
2798 void *key, obd_count vallen, void *val)
2800 struct ptlrpc_request *req;
2801 struct obd_device *obd = exp->exp_obd;
2802 struct obd_import *imp = class_exp2cliimp(exp);
2803 struct llog_ctxt *ctxt;
2804 int rc, size = keylen;
2805 char *bufs[1] = {key};
2808 if (keylen == strlen("next_id") &&
2809 memcmp(key, "next_id", strlen("next_id")) == 0) {
2810 if (vallen != sizeof(obd_id))
2812 obd->u.cli.cl_oscc.oscc_next_id = *((obd_id*)val) + 1;
2813 CDEBUG(D_HA, "%s: set oscc_next_id = "LPU64"\n",
2814 exp->exp_obd->obd_name,
2815 obd->u.cli.cl_oscc.oscc_next_id);
2820 if (keylen == strlen("growth_count") &&
2821 memcmp(key, "growth_count", strlen("growth_count")) == 0) {
2822 if (vallen != sizeof(int))
2824 obd->u.cli.cl_oscc.oscc_grow_count = *((int*)val);
2828 if (keylen == strlen("unlinked") &&
2829 memcmp(key, "unlinked", keylen) == 0) {
2830 struct osc_creator *oscc = &obd->u.cli.cl_oscc;
2831 spin_lock(&oscc->oscc_lock);
2832 oscc->oscc_flags &= ~OSCC_FLAG_NOSPC;
2833 spin_unlock(&oscc->oscc_lock);
2838 if (keylen == strlen("initial_recov") &&
2839 memcmp(key, "initial_recov", strlen("initial_recov")) == 0) {
2840 struct obd_import *imp = exp->exp_obd->u.cli.cl_import;
2841 if (vallen != sizeof(int))
2843 imp->imp_initial_recov = *(int *)val;
2844 CDEBUG(D_HA, "%s: set imp_no_init_recov = %d\n",
2845 exp->exp_obd->obd_name,
2846 imp->imp_initial_recov);
2850 if (keylen < strlen("mds_conn") ||
2851 memcmp(key, "mds_conn", strlen("mds_conn")) != 0)
2855 req = ptlrpc_prep_req(imp, OST_SET_INFO, 1, &size, bufs);
2859 req->rq_replen = lustre_msg_size(0, NULL);
2860 rc = ptlrpc_queue_wait(req);
2861 ptlrpc_req_finished(req);
2863 ctxt = llog_get_context(exp->exp_obd, LLOG_UNLINK_ORIG_CTXT);
2866 rc = llog_initiator_connect(ctxt);
2868 CERROR("cannot establish the connect for ctxt %p: %d\n",
2872 imp->imp_server_timeout = 1;
2873 CDEBUG(D_HA, "pinging OST %s\n", imp->imp_target_uuid.uuid);
2874 imp->imp_pingable = 1;
2880 static struct llog_operations osc_size_repl_logops = {
2881 lop_cancel: llog_obd_repl_cancel
2884 static struct llog_operations osc_unlink_orig_logops;
2885 static int osc_llog_init(struct obd_device *obd, struct obd_device *tgt,
2886 int count, struct llog_catid *catid)
2891 osc_unlink_orig_logops = llog_lvfs_ops;
2892 osc_unlink_orig_logops.lop_setup = llog_obd_origin_setup;
2893 osc_unlink_orig_logops.lop_cleanup = llog_obd_origin_cleanup;
2894 osc_unlink_orig_logops.lop_add = llog_obd_origin_add;
2895 osc_unlink_orig_logops.lop_connect = llog_origin_connect;
2897 rc = llog_setup(obd, LLOG_UNLINK_ORIG_CTXT, tgt, count,
2898 &catid->lci_logid, &osc_unlink_orig_logops);
2902 rc = llog_setup(obd, LLOG_SIZE_REPL_CTXT, tgt, count, NULL,
2903 &osc_size_repl_logops);
2907 static int osc_llog_finish(struct obd_device *obd, int count)
2912 rc = llog_cleanup(llog_get_context(obd, LLOG_UNLINK_ORIG_CTXT));
2916 rc = llog_cleanup(llog_get_context(obd, LLOG_SIZE_REPL_CTXT));
2921 static int osc_connect(struct lustre_handle *exph,
2922 struct obd_device *obd, struct obd_uuid *cluuid)
2926 rc = client_connect_import(exph, obd, cluuid);
2931 static int osc_disconnect(struct obd_export *exp, int flags)
2933 struct obd_device *obd = class_exp2obd(exp);
2934 struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
2937 if (obd->u.cli.cl_conn_count == 1)
2938 /* flush any remaining cancel messages out to the target */
2939 llog_sync(ctxt, exp);
2941 rc = client_disconnect_export(exp, flags);
2945 static int osc_import_event(struct obd_device *obd,
2946 struct obd_import *imp,
2947 enum obd_import_event event)
2949 struct client_obd *cli;
2952 LASSERT(imp->imp_obd == obd);
2955 case IMP_EVENT_DISCON: {
2956 /* Only do this on the MDS OSC's */
2957 if (imp->imp_server_timeout) {
2958 struct osc_creator *oscc = &obd->u.cli.cl_oscc;
2960 spin_lock(&oscc->oscc_lock);
2961 oscc->oscc_flags |= OSCC_FLAG_RECOVERING;
2962 spin_unlock(&oscc->oscc_lock);
2967 case IMP_EVENT_INACTIVE: {
2968 if (obd->obd_observer)
2969 rc = obd_notify(obd->obd_observer, obd, 0);
2972 case IMP_EVENT_INVALIDATE: {
2973 struct ldlm_namespace *ns = obd->obd_namespace;
2977 spin_lock(&cli->cl_loi_list_lock);
2978 cli->cl_avail_grant = 0;
2979 cli->cl_lost_grant = 0;
2980 /* all pages go to failing rpcs due to the invalid import */
2981 osc_check_rpcs(cli);
2982 spin_unlock(&cli->cl_loi_list_lock);
2984 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
2988 case IMP_EVENT_ACTIVE: {
2989 /* Only do this on the MDS OSC's */
2990 if (imp->imp_server_timeout) {
2991 struct osc_creator *oscc = &obd->u.cli.cl_oscc;
2993 spin_lock(&oscc->oscc_lock);
2994 oscc->oscc_flags &= ~OSCC_FLAG_NOSPC;
2995 spin_unlock(&oscc->oscc_lock);
2997 if (obd->obd_observer)
2998 rc = obd_notify(obd->obd_observer, obd, 1);
3002 CERROR("Unknown import event %d\n", event);
3008 int osc_setup(struct obd_device *obd, obd_count len, void *buf)
3012 rc = ptlrpcd_addref();
3016 rc = client_obd_setup(obd, len, buf);
3020 struct lprocfs_static_vars lvars;
3022 lprocfs_init_vars(osc, &lvars);
3023 if (lprocfs_obd_setup(obd, lvars.obd_vars) == 0) {
3024 lproc_osc_attach_seqstat(obd);
3025 ptlrpc_lprocfs_register_obd(obd);
3034 int osc_cleanup(struct obd_device *obd, int flags)
3036 struct osc_creator *oscc = &obd->u.cli.cl_oscc;
3039 ptlrpc_lprocfs_unregister_obd(obd);
3040 lprocfs_obd_cleanup(obd);
3042 spin_lock(&oscc->oscc_lock);
3043 oscc->oscc_flags &= ~OSCC_FLAG_RECOVERING;
3044 oscc->oscc_flags |= OSCC_FLAG_EXITING;
3045 spin_unlock(&oscc->oscc_lock);
3047 rc = client_obd_cleanup(obd, flags);
3053 struct obd_ops osc_obd_ops = {
3054 .o_owner = THIS_MODULE,
3055 .o_setup = osc_setup,
3056 .o_cleanup = osc_cleanup,
3057 .o_connect = osc_connect,
3058 .o_disconnect = osc_disconnect,
3059 .o_statfs = osc_statfs,
3060 .o_packmd = osc_packmd,
3061 .o_unpackmd = osc_unpackmd,
3062 .o_create = osc_create,
3063 .o_destroy = osc_destroy,
3064 .o_getattr = osc_getattr,
3065 .o_getattr_async = osc_getattr_async,
3066 .o_setattr = osc_setattr,
3068 .o_brw_async = osc_brw_async,
3069 .o_prep_async_page = osc_prep_async_page,
3070 .o_queue_async_io = osc_queue_async_io,
3071 .o_set_async_flags = osc_set_async_flags,
3072 .o_queue_group_io = osc_queue_group_io,
3073 .o_trigger_group_io = osc_trigger_group_io,
3074 .o_teardown_async_page = osc_teardown_async_page,
3075 .o_punch = osc_punch,
3077 .o_enqueue = osc_enqueue,
3078 .o_match = osc_match,
3079 .o_change_cbdata = osc_change_cbdata,
3080 .o_cancel = osc_cancel,
3081 .o_cancel_unused = osc_cancel_unused,
3082 .o_iocontrol = osc_iocontrol,
3083 .o_get_info = osc_get_info,
3084 .o_set_info = osc_set_info,
3085 .o_import_event = osc_import_event,
3086 .o_llog_init = osc_llog_init,
3087 .o_llog_finish = osc_llog_finish,
3090 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
3091 struct obd_ops sanosc_obd_ops = {
3092 .o_owner = THIS_MODULE,
3093 .o_cleanup = client_obd_cleanup,
3094 .o_connect = osc_connect,
3095 .o_disconnect = client_disconnect_export,
3096 .o_statfs = osc_statfs,
3097 .o_packmd = osc_packmd,
3098 .o_unpackmd = osc_unpackmd,
3099 .o_create = osc_real_create,
3100 .o_destroy = osc_destroy,
3101 .o_getattr = osc_getattr,
3102 .o_getattr_async = osc_getattr_async,
3103 .o_setattr = osc_setattr,
3104 .o_setup = client_sanobd_setup,
3105 .o_brw = sanosc_brw,
3106 .o_punch = osc_punch,
3108 .o_enqueue = osc_enqueue,
3109 .o_match = osc_match,
3110 .o_change_cbdata = osc_change_cbdata,
3111 .o_cancel = osc_cancel,
3112 .o_cancel_unused = osc_cancel_unused,
3113 .o_iocontrol = osc_iocontrol,
3114 .o_import_event = osc_import_event,
3115 .o_llog_init = osc_llog_init,
3116 .o_llog_finish = osc_llog_finish,
3120 int __init osc_init(void)
3122 struct lprocfs_static_vars lvars;
3123 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
3124 struct lprocfs_static_vars sanlvars;
3129 lprocfs_init_vars(osc, &lvars);
3130 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
3131 lprocfs_init_vars(osc, &sanlvars);
3134 rc = class_register_type(&osc_obd_ops, lvars.module_vars,
3139 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
3140 rc = class_register_type(&sanosc_obd_ops, sanlvars.module_vars,
3141 LUSTRE_SANOSC_NAME);
3143 class_unregister_type(LUSTRE_OSC_NAME);
3150 static void /*__exit*/ osc_exit(void)
3152 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
3153 class_unregister_type(LUSTRE_SANOSC_NAME);
3155 class_unregister_type(LUSTRE_OSC_NAME);
3158 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
3159 MODULE_DESCRIPTION("Lustre Object Storage Client (OSC)");
3160 MODULE_LICENSE("GPL");
3162 module_init(osc_init);
3163 module_exit(osc_exit);