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 <libcfs/kp30.h>
53 #include <linux/lustre_net.h>
54 #include <linux/lustre_sec.h>
55 #include <lustre/lustre_user.h>
56 #include <linux/obd_ost.h>
57 #include <linux/obd_lov.h>
63 #include <linux/lustre_ha.h>
64 #include <linux/lprocfs_status.h>
65 #include <linux/lustre_log.h>
66 #include "osc_internal.h"
68 /* Pack OSC object metadata for disk storage (LE byte order). */
69 static int osc_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
70 struct lov_stripe_md *lsm)
75 lmm_size = sizeof(**lmmp);
80 OBD_FREE(*lmmp, lmm_size);
86 OBD_ALLOC(*lmmp, lmm_size);
92 LASSERT(lsm->lsm_object_id);
93 LASSERT(lsm->lsm_object_gr);
94 (*lmmp)->lmm_object_id = cpu_to_le64(lsm->lsm_object_id);
95 (*lmmp)->lmm_object_gr = cpu_to_le64(lsm->lsm_object_gr);
101 /* Unpack OSC object metadata from disk storage (LE byte order). */
102 static int osc_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
103 struct lov_mds_md *lmm, int lmm_bytes)
109 if (lmm_bytes < sizeof (*lmm)) {
110 CERROR("lov_mds_md too small: %d, need %d\n",
111 lmm_bytes, (int)sizeof(*lmm));
114 /* XXX LOV_MAGIC etc check? */
116 if (lmm->lmm_object_id == 0) {
117 CERROR("lov_mds_md: zero lmm_object_id\n");
122 lsm_size = lov_stripe_md_size(1);
126 if (*lsmp != NULL && lmm == NULL) {
127 OBD_FREE(*lsmp, lsm_size);
133 OBD_ALLOC(*lsmp, lsm_size);
136 loi_init((*lsmp)->lsm_oinfo);
140 /* XXX zero *lsmp? */
141 (*lsmp)->lsm_object_id = le64_to_cpu (lmm->lmm_object_id);
142 (*lsmp)->lsm_object_gr = le64_to_cpu (lmm->lmm_object_gr);
143 LASSERT((*lsmp)->lsm_object_id);
144 LASSERT((*lsmp)->lsm_object_gr);
147 (*lsmp)->lsm_maxbytes = LUSTRE_STRIPE_MAXBYTES;
152 static int osc_getattr_interpret(struct ptlrpc_request *req,
153 struct osc_getattr_async_args *aa, int rc)
155 struct ost_body *body;
161 body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
163 CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
164 memcpy(aa->aa_oa, &body->oa, sizeof(*aa->aa_oa));
166 /* This should really be sent by the OST */
167 aa->aa_oa->o_blksize = PTLRPC_MAX_BRW_SIZE;
168 aa->aa_oa->o_valid |= OBD_MD_FLBLKSZ;
170 CERROR("can't unpack ost_body\n");
172 aa->aa_oa->o_valid = 0;
178 static int osc_getattr_async(struct obd_export *exp, struct obdo *oa,
179 struct lov_stripe_md *md,
180 struct ptlrpc_request_set *set)
182 struct ptlrpc_request *request;
183 struct ost_body *body;
184 int size = sizeof(*body);
185 struct osc_getattr_async_args *aa;
188 request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
189 OST_GETATTR, 1, &size, NULL);
193 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
194 memcpy(&body->oa, oa, sizeof(*oa));
196 request->rq_replen = lustre_msg_size(1, &size);
197 request->rq_interpret_reply = osc_getattr_interpret;
199 LASSERT (sizeof (*aa) <= sizeof (request->rq_async_args));
200 aa = (struct osc_getattr_async_args *)&request->rq_async_args;
203 ptlrpc_set_add_req (set, request);
207 static int osc_getattr(struct obd_export *exp, struct obdo *oa,
208 struct lov_stripe_md *md)
210 struct ptlrpc_request *request;
211 struct ost_body *body;
212 int rc, size = sizeof(*body);
215 request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
216 OST_GETATTR, 1, &size, NULL);
220 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
221 memcpy(&body->oa, oa, sizeof(*oa));
223 request->rq_replen = lustre_msg_size(1, &size);
225 rc = ptlrpc_queue_wait(request);
227 CERROR("%s failed: rc = %d\n", __FUNCTION__, rc);
231 body = lustre_swab_repbuf(request, 0, sizeof (*body),
232 lustre_swab_ost_body);
234 CERROR ("can't unpack ost_body\n");
235 GOTO (out, rc = -EPROTO);
238 CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);
239 memcpy(oa, &body->oa, sizeof(*oa));
241 /* This should really be sent by the OST */
242 oa->o_blksize = PTLRPC_MAX_BRW_SIZE;
243 oa->o_valid |= OBD_MD_FLBLKSZ;
247 ptlrpc_req_finished(request);
251 static int osc_setattr(struct obd_export *exp, struct obdo *oa,
252 struct lov_stripe_md *md, struct obd_trans_info *oti)
254 struct ptlrpc_request *request;
255 struct ost_body *body;
256 int rc, size = sizeof(*body);
259 LASSERT(!(oa->o_valid & OBD_MD_FLGROUP) || oa->o_gr > 0);
261 request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
262 OST_SETATTR, 1, &size, NULL);
266 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof(*body));
267 memcpy(&body->oa, oa, sizeof(*oa));
269 request->rq_replen = lustre_msg_size(1, &size);
271 rc = ptlrpc_queue_wait(request);
275 body = lustre_swab_repbuf(request, 0, sizeof(*body),
276 lustre_swab_ost_body);
278 GOTO(out, rc = -EPROTO);
280 memcpy(oa, &body->oa, sizeof(*oa));
284 ptlrpc_req_finished(request);
288 int osc_real_create(struct obd_export *exp, struct obdo *oa,
289 struct lov_stripe_md **ea, struct obd_trans_info *oti)
291 struct ptlrpc_request *request;
292 struct ost_body *body;
293 struct lov_stripe_md *lsm;
294 int rc, size = sizeof(*body);
302 rc = obd_alloc_memmd(exp, &lsm);
307 request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
308 OST_CREATE, 1, &size, NULL);
310 GOTO(out, rc = -ENOMEM);
312 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
313 memcpy(&body->oa, oa, sizeof(body->oa));
315 request->rq_replen = lustre_msg_size(1, &size);
316 if (oa->o_valid & OBD_MD_FLINLINE) {
317 LASSERT((oa->o_valid & OBD_MD_FLFLAGS) &&
318 oa->o_flags == OBD_FL_DELORPHAN);
319 DEBUG_REQ(D_HA, request,
320 "delorphan from OST integration");
321 /* Don't resend the delorphan request */
322 request->rq_no_resend = request->rq_no_delay = 1;
325 rc = ptlrpc_queue_wait(request);
329 body = lustre_swab_repbuf(request, 0, sizeof(*body),
330 lustre_swab_ost_body);
332 CERROR ("can't unpack ost_body\n");
333 GOTO (out_req, rc = -EPROTO);
336 memcpy(oa, &body->oa, sizeof(*oa));
338 /* This should really be sent by the OST */
339 oa->o_blksize = PTLRPC_MAX_BRW_SIZE;
340 oa->o_valid |= OBD_MD_FLBLKSZ;
342 /* XXX LOV STACKING: the lsm that is passed to us from LOV does not
343 * have valid lsm_oinfo data structs, so don't go touching that.
344 * This needs to be fixed in a big way.
346 lsm->lsm_object_id = oa->o_id;
347 lsm->lsm_object_gr = oa->o_gr;
351 oti->oti_transno = request->rq_repmsg->transno;
353 if (oa->o_valid & OBD_MD_FLCOOKIE) {
354 if (!oti->oti_logcookies)
355 oti_alloc_cookies(oti, 1);
356 memcpy(oti->oti_logcookies, obdo_logcookie(oa),
357 sizeof(oti->oti_onecookie));
361 CDEBUG(D_HA, "transno: "LPD64"\n", request->rq_repmsg->transno);
364 ptlrpc_req_finished(request);
367 obd_free_memmd(exp, &lsm);
371 static int osc_punch(struct obd_export *exp, struct obdo *oa,
372 struct lov_stripe_md *md, obd_size start,
373 obd_size end, struct obd_trans_info *oti)
375 struct ptlrpc_request *request;
376 struct ost_body *body;
377 int rc, size = sizeof(*body);
385 request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
386 OST_PUNCH, 1, &size, NULL);
390 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
391 memcpy(&body->oa, oa, sizeof(*oa));
393 /* overload the size and blocks fields in the oa with start/end */
394 body->oa.o_size = start;
395 body->oa.o_blocks = end;
396 body->oa.o_valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
398 request->rq_replen = lustre_msg_size(1, &size);
400 rc = ptlrpc_queue_wait(request);
404 body = lustre_swab_repbuf (request, 0, sizeof (*body),
405 lustre_swab_ost_body);
407 CERROR ("can't unpack ost_body\n");
408 GOTO (out, rc = -EPROTO);
411 memcpy(oa, &body->oa, sizeof(*oa));
415 ptlrpc_req_finished(request);
419 static int osc_sync(struct obd_export *exp, struct obdo *oa,
420 struct lov_stripe_md *md, obd_size start, obd_size end)
422 struct ptlrpc_request *request;
423 struct ost_body *body;
424 int rc, size = sizeof(*body);
432 request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
433 OST_SYNC, 1, &size, NULL);
437 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
438 memcpy(&body->oa, oa, sizeof(*oa));
440 /* overload the size and blocks fields in the oa with start/end */
441 body->oa.o_size = start;
442 body->oa.o_blocks = end;
443 body->oa.o_valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS);
445 request->rq_replen = lustre_msg_size(1, &size);
447 rc = ptlrpc_queue_wait(request);
451 body = lustre_swab_repbuf(request, 0, sizeof(*body),
452 lustre_swab_ost_body);
454 CERROR ("can't unpack ost_body\n");
455 GOTO (out, rc = -EPROTO);
458 memcpy(oa, &body->oa, sizeof(*oa));
462 ptlrpc_req_finished(request);
466 static int osc_destroy(struct obd_export *exp, struct obdo *oa,
467 struct lov_stripe_md *ea, struct obd_trans_info *oti)
469 struct ptlrpc_request *request;
470 struct ost_body *body;
471 int rc, size = sizeof(*body);
479 request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
480 OST_DESTROY, 1, &size, NULL);
484 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
486 if (oti != NULL && oa->o_valid & OBD_MD_FLCOOKIE) {
487 memcpy(obdo_logcookie(oa), oti->oti_logcookies,
488 sizeof(*oti->oti_logcookies));
489 oti->oti_logcookies++;
492 memcpy(&body->oa, oa, sizeof(*oa));
493 request->rq_replen = lustre_msg_size(1, &size);
495 rc = ptlrpc_queue_wait(request);
502 body = lustre_swab_repbuf(request, 0, sizeof(*body),
503 lustre_swab_ost_body);
505 CERROR ("Can't unpack body\n");
506 GOTO (out, rc = -EPROTO);
509 memcpy(oa, &body->oa, sizeof(*oa));
513 ptlrpc_req_finished(request);
517 static void osc_announce_cached(struct client_obd *cli, struct obdo *oa,
520 obd_valid bits = OBD_MD_FLBLOCKS|OBD_MD_FLGRANT;
522 LASSERT(!(oa->o_valid & bits));
525 spin_lock(&cli->cl_loi_list_lock);
526 oa->o_dirty = cli->cl_dirty;
527 oa->o_undirty = cli->cl_dirty_max - oa->o_dirty;
528 oa->o_grant = cli->cl_avail_grant;
529 oa->o_dropped = cli->cl_lost_grant;
530 cli->cl_lost_grant = 0;
531 spin_unlock(&cli->cl_loi_list_lock);
532 CDEBUG(D_CACHE,"dirty: "LPU64" undirty: %u dropped %u grant: "LPU64"\n",
533 oa->o_dirty, oa->o_undirty, oa->o_dropped, oa->o_grant);
536 /* caller must hold loi_list_lock */
537 static void osc_consume_write_grant(struct client_obd *cli,
538 struct osc_async_page *oap)
540 cli->cl_dirty += PAGE_SIZE;
541 cli->cl_avail_grant -= PAGE_SIZE;
542 oap->oap_brw_flags |= OBD_BRW_FROM_GRANT;
543 CDEBUG(D_CACHE, "using %lu grant credits for oap %p\n", PAGE_SIZE, oap);
544 LASSERT(cli->cl_avail_grant >= 0);
547 static unsigned long rpcs_in_flight(struct client_obd *cli)
549 return cli->cl_r_in_flight + cli->cl_w_in_flight;
552 /* caller must hold loi_list_lock */
553 void osc_wake_cache_waiters(struct client_obd *cli)
555 struct list_head *l, *tmp;
556 struct osc_cache_waiter *ocw;
558 list_for_each_safe(l, tmp, &cli->cl_cache_waiters) {
559 /* if we can't dirty more, we must wait until some is written */
560 if (cli->cl_dirty + PAGE_SIZE > cli->cl_dirty_max) {
561 CDEBUG(D_CACHE, "no dirty room: dirty: %ld max %ld\n",
562 cli->cl_dirty, cli->cl_dirty_max);
566 /* if still dirty cache but no grant wait for pending RPCs that
567 * may yet return us some grant before doing sync writes */
568 if (cli->cl_w_in_flight && cli->cl_avail_grant < PAGE_SIZE) {
569 CDEBUG(D_CACHE, "%u BRW writes in flight, no grant\n",
570 cli->cl_w_in_flight);
572 ocw = list_entry(l, struct osc_cache_waiter, ocw_entry);
573 list_del_init(&ocw->ocw_entry);
574 if (cli->cl_avail_grant < PAGE_SIZE) {
575 /* no more RPCs in flight to return grant, do sync IO */
576 ocw->ocw_rc = -EDQUOT;
577 CDEBUG(D_INODE, "wake oap %p for sync\n", ocw->ocw_oap);
579 osc_consume_write_grant(cli, ocw->ocw_oap);
582 wake_up(&ocw->ocw_waitq);
588 static void osc_update_grant(struct client_obd *cli, struct ost_body *body)
590 spin_lock(&cli->cl_loi_list_lock);
591 CDEBUG(D_CACHE, "got "LPU64" extra grant\n", body->oa.o_grant);
592 cli->cl_avail_grant += body->oa.o_grant;
593 /* waiters are woken in brw_interpret_oap */
594 spin_unlock(&cli->cl_loi_list_lock);
597 /* We assume that the reason this OSC got a short read is because it read
598 * beyond the end of a stripe file; i.e. lustre is reading a sparse file
599 * via the LOV, and it _knows_ it's reading inside the file, it's just that
600 * this stripe never got written at or beyond this stripe offset yet. */
601 static void handle_short_read(int nob_read, obd_count page_count,
602 struct brw_page *pga)
606 /* skip bytes read OK */
607 while (nob_read > 0) {
608 LASSERT (page_count > 0);
610 if (pga->count > nob_read) {
611 /* EOF inside this page */
612 ptr = kmap(pga->pg) + (pga->page_offset & ~PAGE_MASK);
613 memset(ptr + nob_read, 0, pga->count - nob_read);
620 nob_read -= pga->count;
625 /* zero remaining pages */
626 while (page_count-- > 0) {
627 ptr = kmap(pga->pg) + (pga->page_offset & ~PAGE_MASK);
628 memset(ptr, 0, pga->count);
634 static int check_write_rcs(struct ptlrpc_request *request,
635 int requested_nob, int niocount,
636 obd_count page_count, struct brw_page *pga)
640 /* return error if any niobuf was in error */
641 remote_rcs = lustre_swab_repbuf(request, 1,
642 sizeof(*remote_rcs) * niocount, NULL);
643 if (remote_rcs == NULL) {
644 CERROR("Missing/short RC vector on BRW_WRITE reply\n");
647 if (lustre_msg_swabbed(request->rq_repmsg))
648 for (i = 0; i < niocount; i++)
649 __swab32s(&remote_rcs[i]);
651 for (i = 0; i < niocount; i++) {
652 if (remote_rcs[i] < 0)
653 return(remote_rcs[i]);
655 if (remote_rcs[i] != 0) {
656 CERROR("rc[%d] invalid (%d) req %p\n",
657 i, remote_rcs[i], request);
662 if (request->rq_bulk->bd_nob_transferred != requested_nob) {
663 CERROR("Unexpected # bytes transferred: %d (requested %d)\n",
664 requested_nob, request->rq_bulk->bd_nob_transferred);
671 static inline int can_merge_pages(struct brw_page *p1, struct brw_page *p2)
673 if (p1->flag != p2->flag) {
674 unsigned mask = ~OBD_BRW_FROM_GRANT;
676 /* warn if we try to combine flags that we don't know to be
678 if ((p1->flag & mask) != (p2->flag & mask))
679 CERROR("is it ok to have flags 0x%x and 0x%x in the "
680 "same brw?\n", p1->flag, p2->flag);
684 return (p1->disk_offset + p1->count == p2->disk_offset);
688 static obd_count cksum_pages(int nob, obd_count page_count,
689 struct brw_page *pga)
695 LASSERT (page_count > 0);
698 ost_checksum(&cksum, ptr + (pga->off & (PAGE_SIZE - 1)),
699 pga->count > nob ? nob : pga->count);
711 static int osc_brw_prep_request(int cmd, struct obd_import *imp,struct obdo *oa,
712 struct lov_stripe_md *lsm, obd_count page_count,
713 struct brw_page *pga, int *requested_nobp,
714 int *niocountp, struct ptlrpc_request **reqp)
716 struct ptlrpc_request *req;
717 struct ptlrpc_bulk_desc *desc;
718 struct client_obd *cli = &imp->imp_obd->u.cli;
719 struct ost_body *body;
720 struct obd_ioobj *ioobj;
721 struct niobuf_remote *niobuf;
729 opc = ((cmd & OBD_BRW_WRITE) != 0) ? OST_WRITE : OST_READ;
731 for (niocount = i = 1; i < page_count; i++)
732 if (!can_merge_pages(&pga[i - 1], &pga[i]))
735 size[0] = sizeof(*body);
736 size[1] = sizeof(*ioobj);
737 size[2] = niocount * sizeof(*niobuf);
739 req = ptlrpc_prep_req(imp, LUSTRE_OBD_VERSION, opc, 3, size, NULL);
743 if (opc == OST_WRITE)
744 desc = ptlrpc_prep_bulk_imp (req, page_count,
745 BULK_GET_SOURCE, OST_BULK_PORTAL);
747 desc = ptlrpc_prep_bulk_imp (req, page_count,
748 BULK_PUT_SINK, OST_BULK_PORTAL);
750 GOTO(out, rc = -ENOMEM);
751 /* NB request now owns desc and will free it when it gets freed */
753 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
754 ioobj = lustre_msg_buf(req->rq_reqmsg, 1, sizeof(*ioobj));
755 niobuf = lustre_msg_buf(req->rq_reqmsg, 2, niocount * sizeof(*niobuf));
757 memcpy(&body->oa, oa, sizeof(*oa));
759 obdo_to_ioobj(oa, ioobj);
760 ioobj->ioo_bufcnt = niocount;
762 LASSERT (page_count > 0);
764 for (requested_nob = i = 0; i < page_count; i++, niobuf++) {
765 struct brw_page *pg = &pga[i];
766 struct brw_page *pg_prev = pg - 1;
768 LASSERT(pg->count > 0);
769 LASSERTF((pg->page_offset & ~PAGE_MASK)+ pg->count <= PAGE_SIZE,
770 "i: %d pg: %p pg_off: "LPU64", count: %u\n", i, pg,
771 pg->page_offset, pg->count);
772 LASSERTF(i == 0 || pg->disk_offset > pg_prev->disk_offset,
773 "i %d p_c %u pg %p [pri %lu ind %lu] off "LPU64
774 " prev_pg %p [pri %lu ind %lu] off "LPU64"\n",
776 pg->pg, pg->pg->private, pg->pg->index, pg->disk_offset,
777 pg_prev->pg, pg_prev->pg->private, pg_prev->pg->index,
778 pg_prev->disk_offset);
780 ptlrpc_prep_bulk_page(desc, pg->pg,
781 pg->page_offset & ~PAGE_MASK, pg->count);
782 requested_nob += pg->count;
784 if (i > 0 && can_merge_pages(pg_prev, pg)) {
786 niobuf->len += pg->count;
788 niobuf->offset = pg->disk_offset;
789 niobuf->len = pg->count;
790 niobuf->flags = pg->flag;
794 LASSERT((void *)(niobuf - niocount) ==
795 lustre_msg_buf(req->rq_reqmsg, 2, niocount * sizeof(*niobuf)));
796 osc_announce_cached(cli, &body->oa, opc == OST_WRITE ? requested_nob:0);
798 /* size[0] still sizeof (*body) */
799 if (opc == OST_WRITE) {
801 body->oa.o_valid |= OBD_MD_FLCKSUM;
802 body->oa.o_cksum = cksum_pages(requested_nob, page_count, pga);
804 /* 1 RC per niobuf */
805 size[1] = sizeof(__u32) * niocount;
806 req->rq_replen = lustre_msg_size(2, size);
808 /* 1 RC for the whole I/O */
809 req->rq_replen = lustre_msg_size(1, size);
812 *niocountp = niocount;
813 *requested_nobp = requested_nob;
818 ptlrpc_req_finished (req);
822 static int osc_brw_fini_request(struct ptlrpc_request *req, struct obdo *oa,
823 int requested_nob, int niocount,
824 obd_count page_count, struct brw_page *pga,
827 struct client_obd *cli = &req->rq_import->imp_obd->u.cli;
828 struct ost_body *body;
834 body = lustre_swab_repbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
836 CERROR ("Can't unpack body\n");
840 osc_update_grant(cli, body);
841 memcpy(oa, &body->oa, sizeof(*oa));
843 if (req->rq_reqmsg->opc == OST_WRITE) {
845 CERROR ("Unexpected +ve rc %d\n", rc);
848 LASSERT (req->rq_bulk->bd_nob == requested_nob);
850 RETURN(check_write_rcs(req, requested_nob, niocount,
854 if (rc > requested_nob) {
855 CERROR("Unexpected rc %d (%d requested)\n", rc, requested_nob);
859 if (rc != req->rq_bulk->bd_nob_transferred) {
860 CERROR ("Unexpected rc %d (%d transferred)\n",
861 rc, req->rq_bulk->bd_nob_transferred);
865 if (rc < requested_nob)
866 handle_short_read(rc, page_count, pga);
869 if (oa->o_valid & OBD_MD_FLCKSUM) {
870 const struct ptlrpc_peer *peer =
871 &req->rq_import->imp_connection->c_peer;
872 static int cksum_counter;
873 obd_count server_cksum = oa->o_cksum;
874 obd_count cksum = cksum_pages(rc, page_count, pga);
875 char str[PTL_NALFMT_SIZE];
877 ptlrpc_peernid2str(peer, str);
880 if (server_cksum != cksum) {
881 CERROR("Bad checksum: server %x, client %x, server NID "
882 LPX64" (%s)\n", server_cksum, cksum,
883 peer->peer_id.nid, str);
886 } else if ((cksum_counter & (-cksum_counter)) == cksum_counter){
887 CWARN("Checksum %u from "LPX64" (%s) OK: %x\n",
888 cksum_counter, peer->peer_id.nid, str, cksum);
891 static int cksum_missed;
894 if ((cksum_missed & (-cksum_missed)) == cksum_missed)
895 CERROR("Request checksum %u from "LPX64", no reply\n",
897 req->rq_import->imp_connection->c_peer.peer_id.nid);
903 static int osc_brw_internal(int cmd, struct obd_export *exp,struct obdo *oa,
904 struct lov_stripe_md *lsm,
905 obd_count page_count, struct brw_page *pga)
909 struct ptlrpc_request *request;
914 rc = osc_brw_prep_request(cmd, class_exp2cliimp(exp), oa, lsm,
915 page_count, pga, &requested_nob, &niocount,
920 rc = ptlrpc_queue_wait(request);
922 if (rc == -ETIMEDOUT && request->rq_resend) {
923 DEBUG_REQ(D_HA, request, "BULK TIMEOUT");
924 ptlrpc_req_finished(request);
928 rc = osc_brw_fini_request(request, oa, requested_nob, niocount,
929 page_count, pga, rc);
931 ptlrpc_req_finished(request);
935 static int brw_interpret(struct ptlrpc_request *request,
936 struct osc_brw_async_args *aa, int rc)
938 struct obdo *oa = aa->aa_oa;
939 int requested_nob = aa->aa_requested_nob;
940 int niocount = aa->aa_nio_count;
941 obd_count page_count = aa->aa_page_count;
942 struct brw_page *pga = aa->aa_pga;
945 rc = osc_brw_fini_request(request, oa, requested_nob, niocount,
946 page_count, pga, rc);
950 static int async_internal(int cmd, struct obd_export *exp, struct obdo *oa,
951 struct lov_stripe_md *lsm, obd_count page_count,
952 struct brw_page *pga, struct ptlrpc_request_set *set)
954 struct ptlrpc_request *request;
957 struct osc_brw_async_args *aa;
961 rc = osc_brw_prep_request(cmd, class_exp2cliimp(exp), oa, lsm,
962 page_count, pga, &requested_nob, &nio_count,
965 LASSERT(sizeof(*aa) <= sizeof(request->rq_async_args));
966 aa = (struct osc_brw_async_args *)&request->rq_async_args;
968 aa->aa_requested_nob = requested_nob;
969 aa->aa_nio_count = nio_count;
970 aa->aa_page_count = page_count;
973 request->rq_interpret_reply = brw_interpret;
974 ptlrpc_set_add_req(set, request);
980 #define min_t(type,x,y) \
981 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
985 * ugh, we want disk allocation on the target to happen in offset order. we'll
986 * follow sedgewicks advice and stick to the dead simple shellsort -- it'll do
987 * fine for our small page arrays and doesn't require allocation. its an
988 * insertion sort that swaps elements that are strides apart, shrinking the
989 * stride down until its '1' and the array is sorted.
991 static void sort_brw_pages(struct brw_page *array, int num)
998 for (stride = 1; stride < num ; stride = (stride * 3) + 1)
1003 for (i = stride ; i < num ; i++) {
1006 while (j >= stride && array[j - stride].disk_offset >
1008 array[j] = array[j - stride];
1013 } while (stride > 1);
1016 /* make sure we the regions we're passing to elan don't violate its '4
1017 * fragments' constraint. portal headers are a fragment, all full
1018 * PAGE_SIZE long pages count as 1 fragment, and each partial page
1019 * counts as a fragment. I think. see bug 934. */
1020 static obd_count check_elan_limit(struct brw_page *pg, obd_count pages)
1023 int saw_whole_frag = 0;
1026 for (i = 0 ; frags_left && i < pages ; pg++, i++) {
1027 if (pg->count == PAGE_SIZE) {
1028 if (!saw_whole_frag) {
1039 static int osc_brw(int cmd, struct obd_export *exp, struct obdo *oa,
1040 struct lov_stripe_md *lsm, obd_count page_count,
1041 struct brw_page *pga, struct obd_trans_info *oti)
1045 if (cmd == OBD_BRW_CHECK) {
1046 /* The caller just wants to know if there's a chance that this
1047 * I/O can succeed */
1048 struct obd_import *imp = class_exp2cliimp(exp);
1050 if (imp == NULL || imp->imp_invalid)
1055 while (page_count) {
1056 obd_count pages_per_brw;
1059 if (page_count > PTLRPC_MAX_BRW_PAGES)
1060 pages_per_brw = PTLRPC_MAX_BRW_PAGES;
1062 pages_per_brw = page_count;
1064 sort_brw_pages(pga, pages_per_brw);
1065 pages_per_brw = check_elan_limit(pga, pages_per_brw);
1067 rc = osc_brw_internal(cmd, exp, oa, lsm, pages_per_brw, pga);
1072 page_count -= pages_per_brw;
1073 pga += pages_per_brw;
1078 static int osc_brw_async(int cmd, struct obd_export *exp, struct obdo *oa,
1079 struct lov_stripe_md *lsm, obd_count page_count,
1080 struct brw_page *pga, struct ptlrpc_request_set *set,
1081 struct obd_trans_info *oti)
1085 if (cmd == OBD_BRW_CHECK) {
1086 /* The caller just wants to know if there's a chance that this
1087 * I/O can succeed */
1088 struct obd_import *imp = class_exp2cliimp(exp);
1090 if (imp == NULL || imp->imp_invalid)
1095 while (page_count) {
1096 obd_count pages_per_brw;
1099 if (page_count > PTLRPC_MAX_BRW_PAGES)
1100 pages_per_brw = PTLRPC_MAX_BRW_PAGES;
1102 pages_per_brw = page_count;
1104 sort_brw_pages(pga, pages_per_brw);
1105 pages_per_brw = check_elan_limit(pga, pages_per_brw);
1107 rc = async_internal(cmd, exp, oa, lsm, pages_per_brw, pga, set);
1112 page_count -= pages_per_brw;
1113 pga += pages_per_brw;
1118 static void osc_check_rpcs(struct client_obd *cli);
1119 static void osc_exit_cache(struct client_obd *cli, struct osc_async_page *oap,
1121 static void loi_list_maint(struct client_obd *cli, struct lov_oinfo *loi);
1122 static void lop_update_pending(struct client_obd *cli,
1123 struct loi_oap_pages *lop, int cmd, int delta);
1125 /* this is called when a sync waiter receives an interruption. Its job is to
1126 * get the caller woken as soon as possible. If its page hasn't been put in an
1127 * rpc yet it can dequeue immediately. Otherwise it has to mark the rpc as
1128 * desiring interruption which will forcefully complete the rpc once the rpc
1130 static void osc_occ_interrupted(struct oig_callback_context *occ)
1132 struct osc_async_page *oap;
1133 struct loi_oap_pages *lop;
1134 struct lov_oinfo *loi;
1137 /* XXX member_of() */
1138 oap = list_entry(occ, struct osc_async_page, oap_occ);
1140 spin_lock(&oap->oap_cli->cl_loi_list_lock);
1142 oap->oap_interrupted = 1;
1144 /* ok, it's been put in an rpc. */
1145 if (oap->oap_request != NULL) {
1146 ptlrpc_mark_interrupted(oap->oap_request);
1147 ptlrpcd_wake(oap->oap_request);
1151 /* we don't get interruption callbacks until osc_trigger_sync_io()
1152 * has been called and put the sync oaps in the pending/urgent lists.*/
1153 if (!list_empty(&oap->oap_pending_item)) {
1154 list_del_init(&oap->oap_pending_item);
1155 if (oap->oap_async_flags & ASYNC_URGENT)
1156 list_del_init(&oap->oap_urgent_item);
1159 lop = (oap->oap_cmd == OBD_BRW_WRITE) ?
1160 &loi->loi_write_lop : &loi->loi_read_lop;
1161 lop_update_pending(oap->oap_cli, lop, oap->oap_cmd, -1);
1162 loi_list_maint(oap->oap_cli, oap->oap_loi);
1164 oig_complete_one(oap->oap_oig, &oap->oap_occ, 0);
1165 oap->oap_oig = NULL;
1169 spin_unlock(&oap->oap_cli->cl_loi_list_lock);
1172 /* this must be called holding the loi list lock to give coverage to exit_cache,
1173 * async_flag maintenance, and oap_request */
1174 static void osc_ap_completion(struct client_obd *cli, struct obdo *oa,
1175 struct osc_async_page *oap, int sent, int rc)
1177 osc_exit_cache(cli, oap, sent);
1178 oap->oap_async_flags = 0;
1179 oap->oap_interrupted = 0;
1181 if (oap->oap_request != NULL) {
1182 ptlrpc_req_finished(oap->oap_request);
1183 oap->oap_request = NULL;
1186 if (rc == 0 && oa != NULL)
1187 oap->oap_loi->loi_blocks = oa->o_blocks;
1190 oig_complete_one(oap->oap_oig, &oap->oap_occ, rc);
1191 oap->oap_oig = NULL;
1196 oap->oap_caller_ops->ap_completion(oap->oap_caller_data, oap->oap_cmd,
1200 static int brw_interpret_oap(struct ptlrpc_request *request,
1201 struct osc_brw_async_args *aa, int rc)
1203 struct osc_async_page *oap;
1204 struct client_obd *cli;
1205 struct list_head *pos, *n;
1209 do_gettimeofday(&now);
1210 rc = osc_brw_fini_request(request, aa->aa_oa, aa->aa_requested_nob,
1211 aa->aa_nio_count, aa->aa_page_count,
1214 CDEBUG(D_INODE, "request %p aa %p rc %d\n", request, aa, rc);
1217 /* in failout recovery we ignore writeback failure and want
1218 * to just tell llite to unlock the page and continue */
1219 if (request->rq_reqmsg->opc == OST_WRITE &&
1220 (cli->cl_import == NULL || cli->cl_import->imp_invalid)) {
1221 CDEBUG(D_INODE, "flipping to rc 0 imp %p inv %d\n",
1223 cli->cl_import ? cli->cl_import->imp_invalid : -1);
1227 spin_lock(&cli->cl_loi_list_lock);
1229 if (request->rq_reqmsg->opc == OST_WRITE)
1230 lprocfs_stime_record(&cli->cl_write_stime, &now,
1231 &request->rq_rpcd_start);
1233 lprocfs_stime_record(&cli->cl_read_stime, &now,
1234 &request->rq_rpcd_start);
1238 /* We need to decrement before osc_ap_completion->osc_wake_cache_waiters
1239 * is called so we know whether to go to sync BRWs or wait for more
1240 * RPCs to complete */
1241 if (request->rq_reqmsg->opc == OST_WRITE)
1242 cli->cl_w_in_flight--;
1244 cli->cl_r_in_flight--;
1246 /* the caller may re-use the oap after the completion call so
1247 * we need to clean it up a little */
1248 list_for_each_safe(pos, n, &aa->aa_oaps) {
1249 oap = list_entry(pos, struct osc_async_page, oap_rpc_item);
1251 //CDEBUG(D_INODE, "page %p index %lu oap %p\n",
1252 //oap->oap_page, oap->oap_page->index, oap);
1254 list_del_init(&oap->oap_rpc_item);
1255 osc_ap_completion(cli, aa->aa_oa, oap, 1, rc);
1258 osc_wake_cache_waiters(cli);
1259 osc_check_rpcs(cli);
1261 spin_unlock(&cli->cl_loi_list_lock);
1263 obdo_free(aa->aa_oa);
1264 OBD_FREE(aa->aa_pga, aa->aa_page_count * sizeof(struct brw_page));
1269 static struct ptlrpc_request *osc_build_req(struct client_obd *cli,
1270 struct list_head *rpc_list,
1271 int page_count, int cmd)
1273 struct ptlrpc_request *req;
1274 struct brw_page *pga = NULL;
1275 int requested_nob, nio_count;
1276 struct osc_brw_async_args *aa;
1277 struct obdo *oa = NULL;
1278 struct obd_async_page_ops *ops = NULL;
1279 void *caller_data = NULL;
1280 struct list_head *pos;
1283 LASSERT(!list_empty(rpc_list));
1285 OBD_ALLOC(pga, sizeof(*pga) * page_count);
1287 RETURN(ERR_PTR(-ENOMEM));
1291 GOTO(out, req = ERR_PTR(-ENOMEM));
1294 list_for_each(pos, rpc_list) {
1295 struct osc_async_page *oap;
1297 oap = list_entry(pos, struct osc_async_page, oap_rpc_item);
1299 ops = oap->oap_caller_ops;
1300 caller_data = oap->oap_caller_data;
1302 pga[i].disk_offset = oap->oap_obj_off + oap->oap_page_off;
1303 pga[i].page_offset = pga[i].disk_offset;
1304 pga[i].pg = oap->oap_page;
1305 pga[i].count = oap->oap_count;
1306 pga[i].flag = oap->oap_brw_flags;
1307 CDEBUG(0, "put page %p index %lu oap %p flg %x to pga\n",
1308 pga[i].pg, oap->oap_page->index, oap, pga[i].flag);
1312 /* always get the data for the obdo for the rpc */
1313 LASSERT(ops != NULL);
1314 ops->ap_fill_obdo(caller_data, cmd, oa);
1316 sort_brw_pages(pga, page_count);
1317 rc = osc_brw_prep_request(cmd, cli->cl_import, oa, NULL, page_count,
1318 pga, &requested_nob, &nio_count, &req);
1320 CERROR("prep_req failed: %d\n", rc);
1321 GOTO(out, req = ERR_PTR(rc));
1324 LASSERT(sizeof(*aa) <= sizeof(req->rq_async_args));
1325 aa = (struct osc_brw_async_args *)&req->rq_async_args;
1327 aa->aa_requested_nob = requested_nob;
1328 aa->aa_nio_count = nio_count;
1329 aa->aa_page_count = page_count;
1338 OBD_FREE(pga, sizeof(*pga) * page_count);
1343 static void lop_update_pending(struct client_obd *cli,
1344 struct loi_oap_pages *lop, int cmd, int delta)
1346 lop->lop_num_pending += delta;
1347 if (cmd == OBD_BRW_WRITE)
1348 cli->cl_pending_w_pages += delta;
1350 cli->cl_pending_r_pages += delta;
1353 /* the loi lock is held across this function but it's allowed to release
1354 * and reacquire it during its work */
1355 static int osc_send_oap_rpc(struct client_obd *cli, struct lov_oinfo *loi,
1356 int cmd, struct loi_oap_pages *lop)
1358 struct ptlrpc_request *request;
1359 obd_count page_count = 0;
1360 struct list_head *tmp, *pos;
1361 struct osc_async_page *oap = NULL;
1362 struct osc_brw_async_args *aa;
1363 struct obd_async_page_ops *ops;
1364 LIST_HEAD(rpc_list);
1367 /* first we find the pages we're allowed to work with */
1368 list_for_each_safe(pos, tmp, &lop->lop_pending) {
1369 oap = list_entry(pos, struct osc_async_page, oap_pending_item);
1370 ops = oap->oap_caller_ops;
1372 LASSERT(oap->oap_magic == OAP_MAGIC);
1374 /* in llite being 'ready' equates to the page being locked
1375 * until completion unlocks it. commit_write submits a page
1376 * as not ready because its unlock will happen unconditionally
1377 * as the call returns. if we race with commit_write giving
1378 * us that page we dont' want to create a hole in the page
1379 * stream, so we stop and leave the rpc to be fired by
1380 * another dirtier or kupdated interval (the not ready page
1381 * will still be on the dirty list). we could call in
1382 * at the end of ll_file_write to process the queue again. */
1383 if (!(oap->oap_async_flags & ASYNC_READY)) {
1384 int rc = ops->ap_make_ready(oap->oap_caller_data, cmd);
1386 CDEBUG(D_INODE, "oap %p page %p returned %d "
1387 "instead of ready\n", oap,
1391 /* llite is telling us that the page is still
1392 * in commit_write and that we should try
1393 * and put it in an rpc again later. we
1394 * break out of the loop so we don't create
1395 * a hole in the sequence of pages in the rpc
1400 /* the io isn't needed.. tell the checks
1401 * below to complete the rpc with EINTR */
1402 oap->oap_async_flags |= ASYNC_COUNT_STABLE;
1403 oap->oap_count = -EINTR;
1406 oap->oap_async_flags |= ASYNC_READY;
1409 LASSERTF(0, "oap %p page %p returned %d "
1410 "from make_ready\n", oap,
1418 /* take the page out of our book-keeping */
1419 list_del_init(&oap->oap_pending_item);
1420 lop_update_pending(cli, lop, cmd, -1);
1421 list_del_init(&oap->oap_urgent_item);
1423 /* ask the caller for the size of the io as the rpc leaves. */
1424 if (!(oap->oap_async_flags & ASYNC_COUNT_STABLE))
1426 ops->ap_refresh_count(oap->oap_caller_data,cmd);
1427 if (oap->oap_count <= 0) {
1428 CDEBUG(D_CACHE, "oap %p count %d, completing\n", oap,
1430 osc_ap_completion(cli, NULL, oap, 0, oap->oap_count);
1434 /* now put the page back in our accounting */
1435 list_add_tail(&oap->oap_rpc_item, &rpc_list);
1436 if (++page_count >= cli->cl_max_pages_per_rpc)
1440 osc_wake_cache_waiters(cli);
1442 if (page_count == 0)
1445 loi_list_maint(cli, loi);
1446 spin_unlock(&cli->cl_loi_list_lock);
1448 request = osc_build_req(cli, &rpc_list, page_count, cmd);
1449 if (IS_ERR(request)) {
1450 /* this should happen rarely and is pretty bad, it makes the
1451 * pending list not follow the dirty order */
1452 spin_lock(&cli->cl_loi_list_lock);
1453 list_for_each_safe(pos, tmp, &rpc_list) {
1454 oap = list_entry(pos, struct osc_async_page,
1456 list_del_init(&oap->oap_rpc_item);
1458 /* queued sync pages can be torn down while the pages
1459 * were between the pending list and the rpc */
1460 if (oap->oap_interrupted) {
1461 CDEBUG(D_INODE, "oap %p interrupted\n", oap);
1462 osc_ap_completion(cli, NULL, oap, 0,
1467 /* put the page back in the loi/lop lists */
1468 list_add_tail(&oap->oap_pending_item,
1470 lop_update_pending(cli, lop, cmd, 1);
1471 if (oap->oap_async_flags & ASYNC_URGENT)
1472 list_add(&oap->oap_urgent_item,
1475 loi_list_maint(cli, loi);
1476 RETURN(PTR_ERR(request));
1479 LASSERT(sizeof(*aa) <= sizeof(request->rq_async_args));
1480 aa = (struct osc_brw_async_args *)&request->rq_async_args;
1481 INIT_LIST_HEAD(&aa->aa_oaps);
1482 list_splice(&rpc_list, &aa->aa_oaps);
1483 INIT_LIST_HEAD(&rpc_list);
1486 if (cmd == OBD_BRW_READ) {
1487 lprocfs_oh_tally_log2(&cli->cl_read_page_hist, page_count);
1488 lprocfs_oh_tally(&cli->cl_read_rpc_hist, cli->cl_r_in_flight);
1490 lprocfs_oh_tally_log2(&cli->cl_write_page_hist, page_count);
1491 lprocfs_oh_tally(&cli->cl_write_rpc_hist,
1492 cli->cl_w_in_flight);
1496 spin_lock(&cli->cl_loi_list_lock);
1498 if (cmd == OBD_BRW_READ)
1499 cli->cl_r_in_flight++;
1501 cli->cl_w_in_flight++;
1502 /* queued sync pages can be torn down while the pages
1503 * were between the pending list and the rpc */
1504 list_for_each(pos, &aa->aa_oaps) {
1505 oap = list_entry(pos, struct osc_async_page, oap_rpc_item);
1506 if (oap->oap_interrupted) {
1507 CDEBUG(D_INODE, "oap %p in req %p interrupted\n",
1509 ptlrpc_mark_interrupted(request);
1514 CDEBUG(D_INODE, "req %p: %d pages, aa %p. now %dr/%dw in flight\n",
1515 request, page_count, aa, cli->cl_r_in_flight,
1516 cli->cl_w_in_flight);
1518 oap->oap_request = ptlrpc_request_addref(request);
1519 request->rq_interpret_reply = brw_interpret_oap;
1520 ptlrpcd_add_req(request);
1524 static int lop_makes_rpc(struct client_obd *cli, struct loi_oap_pages *lop,
1530 if (lop->lop_num_pending == 0)
1533 /* if we have an invalid import we want to drain the queued pages
1534 * by forcing them through rpcs that immediately fail and complete
1535 * the pages. recovery relies on this to empty the queued pages
1536 * before canceling the locks and evicting down the llite pages */
1537 if (cli->cl_import == NULL || cli->cl_import->imp_invalid)
1540 /* stream rpcs in queue order as long as as there is an urgent page
1541 * queued. this is our cheap solution for good batching in the case
1542 * where writepage marks some random page in the middle of the file as
1543 * urgent because of, say, memory pressure */
1544 if (!list_empty(&lop->lop_urgent))
1547 /* fire off rpcs when we have 'optimal' rpcs as tuned for the wire. */
1548 optimal = cli->cl_max_pages_per_rpc;
1549 if (cmd == OBD_BRW_WRITE) {
1550 /* trigger a write rpc stream as long as there are dirtiers
1551 * waiting for space. as they're waiting, they're not going to
1552 * create more pages to coallesce with what's waiting.. */
1553 if (!list_empty(&cli->cl_cache_waiters))
1556 /* *2 to avoid triggering rpcs that would want to include pages
1557 * that are being queued but which can't be made ready until
1558 * the queuer finishes with the page. this is a wart for
1559 * llite::commit_write() */
1562 if (lop->lop_num_pending >= optimal)
1568 static void on_list(struct list_head *item, struct list_head *list,
1571 if (list_empty(item) && should_be_on)
1572 list_add_tail(item, list);
1573 else if (!list_empty(item) && !should_be_on)
1574 list_del_init(item);
1577 /* maintain the loi's cli list membership invariants so that osc_send_oap_rpc
1578 * can find pages to build into rpcs quickly */
1579 static void loi_list_maint(struct client_obd *cli, struct lov_oinfo *loi)
1581 on_list(&loi->loi_cli_item, &cli->cl_loi_ready_list,
1582 lop_makes_rpc(cli, &loi->loi_write_lop, OBD_BRW_WRITE) ||
1583 lop_makes_rpc(cli, &loi->loi_read_lop, OBD_BRW_READ));
1585 on_list(&loi->loi_write_item, &cli->cl_loi_write_list,
1586 loi->loi_write_lop.lop_num_pending);
1588 on_list(&loi->loi_read_item, &cli->cl_loi_read_list,
1589 loi->loi_read_lop.lop_num_pending);
1592 #define LOI_DEBUG(LOI, STR, args...) \
1593 CDEBUG(D_INODE, "loi ready %d wr %d:%d rd %d:%d " STR, \
1594 !list_empty(&(LOI)->loi_cli_item), \
1595 (LOI)->loi_write_lop.lop_num_pending, \
1596 !list_empty(&(LOI)->loi_write_lop.lop_urgent), \
1597 (LOI)->loi_read_lop.lop_num_pending, \
1598 !list_empty(&(LOI)->loi_read_lop.lop_urgent), \
1601 struct lov_oinfo *osc_next_loi(struct client_obd *cli)
1604 /* first return all objects which we already know to have
1605 * pages ready to be stuffed into rpcs */
1606 if (!list_empty(&cli->cl_loi_ready_list))
1607 RETURN(list_entry(cli->cl_loi_ready_list.next,
1608 struct lov_oinfo, loi_cli_item));
1610 /* then if we have cache waiters, return all objects with queued
1611 * writes. This is especially important when many small files
1612 * have filled up the cache and not been fired into rpcs because
1613 * they don't pass the nr_pending/object threshhold */
1614 if (!list_empty(&cli->cl_cache_waiters) &&
1615 !list_empty(&cli->cl_loi_write_list))
1616 RETURN(list_entry(cli->cl_loi_write_list.next,
1617 struct lov_oinfo, loi_write_item));
1619 /* then return all queued objects when we have an invalid import
1620 * so that they get flushed */
1621 if (cli->cl_import == NULL || cli->cl_import->imp_invalid) {
1622 if (!list_empty(&cli->cl_loi_write_list))
1623 RETURN(list_entry(cli->cl_loi_write_list.next,
1624 struct lov_oinfo, loi_write_item));
1625 if (!list_empty(&cli->cl_loi_read_list))
1626 RETURN(list_entry(cli->cl_loi_read_list.next,
1627 struct lov_oinfo, loi_read_item));
1632 /* called with the loi list lock held */
1633 static void osc_check_rpcs(struct client_obd *cli)
1635 struct lov_oinfo *loi;
1636 int rc = 0, race_counter = 0;
1639 while ((loi = osc_next_loi(cli)) != NULL) {
1640 LOI_DEBUG(loi, "%lu in flight\n", rpcs_in_flight(cli));
1642 if (rpcs_in_flight(cli) >= cli->cl_max_rpcs_in_flight)
1645 /* attempt some read/write balancing by alternating between
1646 * reads and writes in an object. The makes_rpc checks here
1647 * would be redundant if we were getting read/write work items
1648 * instead of objects. we don't want send_oap_rpc to drain a
1649 * partial read pending queue when we're given this object to
1650 * do io on writes while there are cache waiters */
1651 if (lop_makes_rpc(cli, &loi->loi_write_lop, OBD_BRW_WRITE)) {
1652 rc = osc_send_oap_rpc(cli, loi, OBD_BRW_WRITE,
1653 &loi->loi_write_lop);
1661 if (lop_makes_rpc(cli, &loi->loi_read_lop, OBD_BRW_READ)) {
1662 rc = osc_send_oap_rpc(cli, loi, OBD_BRW_READ,
1663 &loi->loi_read_lop);
1672 /* attempt some inter-object balancing by issueing rpcs
1673 * for each object in turn */
1674 if (!list_empty(&loi->loi_cli_item))
1675 list_del_init(&loi->loi_cli_item);
1676 if (!list_empty(&loi->loi_write_item))
1677 list_del_init(&loi->loi_write_item);
1678 if (!list_empty(&loi->loi_read_item))
1679 list_del_init(&loi->loi_read_item);
1681 loi_list_maint(cli, loi);
1683 /* send_oap_rpc fails with 0 when make_ready tells it to
1684 * back off. llite's make_ready does this when it tries
1685 * to lock a page queued for write that is already locked.
1686 * we want to try sending rpcs from many objects, but we
1687 * don't want to spin failing with 0. */
1688 if (race_counter == 10)
1694 /* we're trying to queue a page in the osc so we're subject to the
1695 * 'cl_dirty_max' limit on the number of pages that can be queued in the osc.
1696 * If the osc's queued pages are already at that limit, then we want to sleep
1697 * until there is space in the osc's queue for us. We also may be waiting for
1698 * write credits from the OST if there are RPCs in flight that may return some
1699 * before we fall back to sync writes.
1701 * We need this know our allocation was granted in the presence of signals */
1702 static int ocw_granted(struct client_obd *cli, struct osc_cache_waiter *ocw)
1706 spin_lock(&cli->cl_loi_list_lock);
1707 rc = list_empty(&ocw->ocw_entry) || rpcs_in_flight(cli) == 0;
1708 spin_unlock(&cli->cl_loi_list_lock);
1712 /* Caller must hold loi_list_lock - we drop/regain it if we need to wait for
1713 * grant or cache space. */
1714 static int osc_enter_cache(struct client_obd *cli, struct lov_oinfo *loi,
1715 struct osc_async_page *oap)
1717 struct osc_cache_waiter ocw;
1718 struct l_wait_info lwi = { 0 };
1719 struct timeval start, stop;
1721 CDEBUG(D_CACHE, "dirty: %ld dirty_max: %ld dropped: %lu grant: %lu\n",
1722 cli->cl_dirty, cli->cl_dirty_max, cli->cl_lost_grant,
1723 cli->cl_avail_grant);
1725 if (cli->cl_dirty_max < PAGE_SIZE)
1728 /* Hopefully normal case - cache space and write credits available */
1729 if (cli->cl_dirty + PAGE_SIZE <= cli->cl_dirty_max &&
1730 cli->cl_avail_grant >= PAGE_SIZE) {
1731 /* account for ourselves */
1732 osc_consume_write_grant(cli, oap);
1736 /* Make sure that there are write rpcs in flight to wait for. This
1737 * is a little silly as this object may not have any pending but
1738 * other objects sure might. */
1739 if (cli->cl_w_in_flight) {
1740 list_add_tail(&ocw.ocw_entry, &cli->cl_cache_waiters);
1741 init_waitqueue_head(&ocw.ocw_waitq);
1745 loi_list_maint(cli, loi);
1746 osc_check_rpcs(cli);
1747 spin_unlock(&cli->cl_loi_list_lock);
1749 CDEBUG(0, "sleeping for cache space\n");
1750 do_gettimeofday(&start);
1751 l_wait_event(ocw.ocw_waitq, ocw_granted(cli, &ocw), &lwi);
1752 do_gettimeofday(&stop);
1753 spin_lock(&cli->cl_loi_list_lock);
1754 lprocfs_stime_record(&cli->cl_enter_stime, &stop, &start);
1755 if (!list_empty(&ocw.ocw_entry)) {
1756 list_del(&ocw.ocw_entry);
1765 /* the companion to enter_cache, called when an oap is no longer part of the
1766 * dirty accounting.. so writeback completes or truncate happens before writing
1767 * starts. must be called with the loi lock held. */
1768 static void osc_exit_cache(struct client_obd *cli, struct osc_async_page *oap,
1773 if (!(oap->oap_brw_flags & OBD_BRW_FROM_GRANT)) {
1778 oap->oap_brw_flags &= ~OBD_BRW_FROM_GRANT;
1779 cli->cl_dirty -= PAGE_SIZE;
1781 cli->cl_lost_grant += PAGE_SIZE;
1782 CDEBUG(D_CACHE, "lost grant: %lu avail grant: %lu dirty: %lu\n",
1783 cli->cl_lost_grant, cli->cl_avail_grant, cli->cl_dirty);
1789 int osc_prep_async_page(struct obd_export *exp, struct lov_stripe_md *lsm,
1790 struct lov_oinfo *loi, struct page *page,
1791 obd_off offset, struct obd_async_page_ops *ops,
1792 void *data, void **res)
1794 struct osc_async_page *oap;
1797 OBD_ALLOC(oap, sizeof(*oap));
1801 oap->oap_magic = OAP_MAGIC;
1802 oap->oap_cli = &exp->exp_obd->u.cli;
1805 oap->oap_caller_ops = ops;
1806 oap->oap_caller_data = data;
1808 oap->oap_page = page;
1809 oap->oap_obj_off = offset;
1811 INIT_LIST_HEAD(&oap->oap_pending_item);
1812 INIT_LIST_HEAD(&oap->oap_urgent_item);
1813 INIT_LIST_HEAD(&oap->oap_rpc_item);
1815 oap->oap_occ.occ_interrupted = osc_occ_interrupted;
1817 CDEBUG(D_CACHE, "oap %p page %p obj off "LPU64"\n", oap, page, offset);
1822 static int osc_queue_async_io(struct obd_export *exp, struct lov_stripe_md *lsm,
1823 struct lov_oinfo *loi, void *cookie,
1824 int cmd, obd_off off, int count,
1825 obd_flags brw_flags, enum async_flags async_flags)
1827 struct client_obd *cli = &exp->exp_obd->u.cli;
1828 struct osc_async_page *oap;
1829 struct loi_oap_pages *lop;
1833 oap = OAP_FROM_COOKIE(cookie);
1835 if (cli->cl_import == NULL || cli->cl_import->imp_invalid)
1838 if (!list_empty(&oap->oap_pending_item) ||
1839 !list_empty(&oap->oap_urgent_item) ||
1840 !list_empty(&oap->oap_rpc_item))
1844 loi = &lsm->lsm_oinfo[0];
1846 spin_lock(&cli->cl_loi_list_lock);
1849 oap->oap_async_flags = async_flags;
1850 oap->oap_page_off = off;
1851 oap->oap_count = count;
1852 oap->oap_brw_flags = brw_flags;
1854 if (cmd == OBD_BRW_WRITE) {
1855 rc = osc_enter_cache(cli, loi, oap);
1857 spin_unlock(&cli->cl_loi_list_lock);
1860 lop = &loi->loi_write_lop;
1862 lop = &loi->loi_read_lop;
1865 if (oap->oap_async_flags & ASYNC_URGENT)
1866 list_add(&oap->oap_urgent_item, &lop->lop_urgent);
1867 list_add_tail(&oap->oap_pending_item, &lop->lop_pending);
1868 lop_update_pending(cli, lop, cmd, 1);
1870 loi_list_maint(cli, loi);
1872 LOI_DEBUG(loi, "oap %p page %p added for cmd %d\n", oap, oap->oap_page,
1875 osc_check_rpcs(cli);
1876 spin_unlock(&cli->cl_loi_list_lock);
1881 /* aka (~was & now & flag), but this is more clear :) */
1882 #define SETTING(was, now, flag) (!(was & flag) && (now & flag))
1884 static int osc_set_async_flags(struct obd_export *exp,
1885 struct lov_stripe_md *lsm,
1886 struct lov_oinfo *loi, void *cookie,
1887 obd_flags async_flags)
1889 struct client_obd *cli = &exp->exp_obd->u.cli;
1890 struct loi_oap_pages *lop;
1891 struct osc_async_page *oap;
1895 oap = OAP_FROM_COOKIE(cookie);
1897 if (cli->cl_import == NULL || cli->cl_import->imp_invalid)
1901 loi = &lsm->lsm_oinfo[0];
1903 if (oap->oap_cmd == OBD_BRW_WRITE) {
1904 lop = &loi->loi_write_lop;
1906 lop = &loi->loi_read_lop;
1909 spin_lock(&cli->cl_loi_list_lock);
1911 if (list_empty(&oap->oap_pending_item))
1912 GOTO(out, rc = -EINVAL);
1914 if ((oap->oap_async_flags & async_flags) == async_flags)
1917 if (SETTING(oap->oap_async_flags, async_flags, ASYNC_READY))
1918 oap->oap_async_flags |= ASYNC_READY;
1920 if (SETTING(oap->oap_async_flags, async_flags, ASYNC_URGENT)) {
1921 if (list_empty(&oap->oap_rpc_item)) {
1922 list_add(&oap->oap_urgent_item, &lop->lop_urgent);
1923 loi_list_maint(cli, loi);
1927 LOI_DEBUG(loi, "oap %p page %p has flags %x\n", oap, oap->oap_page,
1928 oap->oap_async_flags);
1930 osc_check_rpcs(cli);
1931 spin_unlock(&cli->cl_loi_list_lock);
1935 static int osc_queue_group_io(struct obd_export *exp, struct lov_stripe_md *lsm,
1936 struct lov_oinfo *loi,
1937 struct obd_io_group *oig, void *cookie,
1938 int cmd, obd_off off, int count,
1939 obd_flags brw_flags,
1940 obd_flags async_flags)
1942 struct client_obd *cli = &exp->exp_obd->u.cli;
1943 struct osc_async_page *oap;
1944 struct loi_oap_pages *lop;
1947 oap = OAP_FROM_COOKIE(cookie);
1949 if (cli->cl_import == NULL || cli->cl_import->imp_invalid)
1952 if (!list_empty(&oap->oap_pending_item) ||
1953 !list_empty(&oap->oap_urgent_item) ||
1954 !list_empty(&oap->oap_rpc_item))
1958 loi = &lsm->lsm_oinfo[0];
1960 spin_lock(&cli->cl_loi_list_lock);
1963 oap->oap_page_off = off;
1964 oap->oap_count = count;
1965 oap->oap_brw_flags = brw_flags;
1966 oap->oap_async_flags = async_flags;
1968 if (cmd == OBD_BRW_WRITE)
1969 lop = &loi->loi_write_lop;
1971 lop = &loi->loi_read_lop;
1973 list_add_tail(&oap->oap_pending_item, &lop->lop_pending_group);
1974 if (oap->oap_async_flags & ASYNC_GROUP_SYNC) {
1976 oig_add_one(oig, &oap->oap_occ);
1979 LOI_DEBUG(loi, "oap %p page %p on group pending\n", oap, oap->oap_page);
1981 spin_unlock(&cli->cl_loi_list_lock);
1986 static void osc_group_to_pending(struct client_obd *cli, struct lov_oinfo *loi,
1987 struct loi_oap_pages *lop, int cmd)
1989 struct list_head *pos, *tmp;
1990 struct osc_async_page *oap;
1992 list_for_each_safe(pos, tmp, &lop->lop_pending_group) {
1993 oap = list_entry(pos, struct osc_async_page, oap_pending_item);
1994 list_del(&oap->oap_pending_item);
1995 list_add_tail(&oap->oap_pending_item, &lop->lop_pending);
1996 list_add(&oap->oap_urgent_item, &lop->lop_urgent);
1997 lop_update_pending(cli, lop, cmd, 1);
1999 loi_list_maint(cli, loi);
2002 static int osc_trigger_group_io(struct obd_export *exp,
2003 struct lov_stripe_md *lsm,
2004 struct lov_oinfo *loi,
2005 struct obd_io_group *oig)
2007 struct client_obd *cli = &exp->exp_obd->u.cli;
2011 loi = &lsm->lsm_oinfo[0];
2013 spin_lock(&cli->cl_loi_list_lock);
2015 osc_group_to_pending(cli, loi, &loi->loi_write_lop, OBD_BRW_WRITE);
2016 osc_group_to_pending(cli, loi, &loi->loi_read_lop, OBD_BRW_READ);
2018 osc_check_rpcs(cli);
2019 spin_unlock(&cli->cl_loi_list_lock);
2024 static int osc_teardown_async_page(struct obd_export *exp,
2025 struct lov_stripe_md *lsm,
2026 struct lov_oinfo *loi, void *cookie)
2028 struct client_obd *cli = &exp->exp_obd->u.cli;
2029 struct loi_oap_pages *lop;
2030 struct osc_async_page *oap;
2034 oap = OAP_FROM_COOKIE(cookie);
2037 loi = &lsm->lsm_oinfo[0];
2039 if (oap->oap_cmd == OBD_BRW_WRITE) {
2040 lop = &loi->loi_write_lop;
2042 lop = &loi->loi_read_lop;
2045 spin_lock(&cli->cl_loi_list_lock);
2047 if (!list_empty(&oap->oap_rpc_item))
2048 GOTO(out, rc = -EBUSY);
2050 osc_exit_cache(cli, oap, 0);
2051 osc_wake_cache_waiters(cli);
2053 if (!list_empty(&oap->oap_urgent_item)) {
2054 list_del_init(&oap->oap_urgent_item);
2055 oap->oap_async_flags &= ~ASYNC_URGENT;
2057 if (!list_empty(&oap->oap_pending_item)) {
2058 list_del_init(&oap->oap_pending_item);
2059 lop_update_pending(cli, lop, oap->oap_cmd, -1);
2061 loi_list_maint(cli, loi);
2063 LOI_DEBUG(loi, "oap %p page %p torn down\n", oap, oap->oap_page);
2065 spin_unlock(&cli->cl_loi_list_lock);
2067 OBD_FREE(oap, sizeof(*oap));
2072 /* Note: caller will lock/unlock, and set uptodate on the pages */
2073 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
2074 static int sanosc_brw_read(struct obd_export *exp, struct obdo *oa,
2075 struct lov_stripe_md *lsm, obd_count page_count,
2076 struct brw_page *pga)
2078 struct ptlrpc_request *request = NULL;
2079 struct ost_body *body;
2080 struct niobuf_remote *nioptr;
2081 struct obd_ioobj *iooptr;
2082 int rc, size[3] = {sizeof(*body)}, mapped = 0;
2086 /* XXX does not handle 'new' brw protocol */
2088 size[1] = sizeof(struct obd_ioobj);
2089 size[2] = page_count * sizeof(*nioptr);
2091 request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
2092 OST_SAN_READ, 3, size, NULL);
2096 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof(*body));
2097 iooptr = lustre_msg_buf(request->rq_reqmsg, 1, sizeof(*iooptr));
2098 nioptr = lustre_msg_buf(request->rq_reqmsg, 2,
2099 sizeof(*nioptr) * page_count);
2101 memcpy(&body->oa, oa, sizeof(body->oa));
2103 obdo_to_ioobj(oa, iooptr);
2104 iooptr->ioo_bufcnt = page_count;
2106 for (mapped = 0; mapped < page_count; mapped++, nioptr++) {
2107 LASSERT(PageLocked(pga[mapped].pg));
2108 LASSERT(mapped == 0 ||
2109 pga[mapped].disk_offset > pga[mapped - 1].disk_offset);
2111 nioptr->offset = pga[mapped].disk_offset;
2112 nioptr->len = pga[mapped].count;
2113 nioptr->flags = pga[mapped].flag;
2116 size[1] = page_count * sizeof(*nioptr);
2117 request->rq_replen = lustre_msg_size(2, size);
2119 rc = ptlrpc_queue_wait(request);
2123 body = lustre_swab_repbuf(request, 0, sizeof(*body),
2124 lustre_swab_ost_body);
2126 CERROR("Can't unpack body\n");
2127 GOTO(out_req, rc = -EPROTO);
2130 memcpy(oa, &body->oa, sizeof(*oa));
2132 swab = lustre_msg_swabbed(request->rq_repmsg);
2133 LASSERT_REPSWAB(request, 1);
2134 nioptr = lustre_msg_buf(request->rq_repmsg, 1, size[1]);
2136 /* nioptr missing or short */
2137 GOTO(out_req, rc = -EPROTO);
2141 for (mapped = 0; mapped < page_count; mapped++, nioptr++) {
2142 struct page *page = pga[mapped].pg;
2143 struct buffer_head *bh;
2147 lustre_swab_niobuf_remote (nioptr);
2149 /* got san device associated */
2150 LASSERT(exp->exp_obd != NULL);
2151 dev = exp->exp_obd->u.cli.cl_sandev;
2154 if (!nioptr->offset) {
2155 CDEBUG(D_PAGE, "hole at ino %lu; index %ld\n",
2156 page->mapping->host->i_ino,
2158 memset(page_address(page), 0, PAGE_SIZE);
2162 if (!page->buffers) {
2163 create_empty_buffers(page, dev, PAGE_SIZE);
2166 clear_bit(BH_New, &bh->b_state);
2167 set_bit(BH_Mapped, &bh->b_state);
2168 bh->b_blocknr = (unsigned long)nioptr->offset;
2170 clear_bit(BH_Uptodate, &bh->b_state);
2172 ll_rw_block(READ, 1, &bh);
2176 /* if buffer already existed, it must be the
2177 * one we mapped before, check it */
2178 LASSERT(!test_bit(BH_New, &bh->b_state));
2179 LASSERT(test_bit(BH_Mapped, &bh->b_state));
2180 LASSERT(bh->b_blocknr == (unsigned long)nioptr->offset);
2182 /* wait it's io completion */
2183 if (test_bit(BH_Lock, &bh->b_state))
2186 if (!test_bit(BH_Uptodate, &bh->b_state))
2187 ll_rw_block(READ, 1, &bh);
2191 /* must do syncronous write here */
2193 if (!buffer_uptodate(bh)) {
2201 ptlrpc_req_finished(request);
2205 static int sanosc_brw_write(struct obd_export *exp, struct obdo *oa,
2206 struct lov_stripe_md *lsm, obd_count page_count,
2207 struct brw_page *pga)
2209 struct ptlrpc_request *request = NULL;
2210 struct ost_body *body;
2211 struct niobuf_remote *nioptr;
2212 struct obd_ioobj *iooptr;
2213 int rc, size[3] = {sizeof(*body)}, mapped = 0;
2217 size[1] = sizeof(struct obd_ioobj);
2218 size[2] = page_count * sizeof(*nioptr);
2220 request = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
2221 OST_SAN_WRITE, 3, size, NULL);
2225 body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof (*body));
2226 iooptr = lustre_msg_buf(request->rq_reqmsg, 1, sizeof (*iooptr));
2227 nioptr = lustre_msg_buf(request->rq_reqmsg, 2,
2228 sizeof (*nioptr) * page_count);
2230 memcpy(&body->oa, oa, sizeof(body->oa));
2232 obdo_to_ioobj(oa, iooptr);
2233 iooptr->ioo_bufcnt = page_count;
2236 for (mapped = 0; mapped < page_count; mapped++, nioptr++) {
2237 LASSERT(PageLocked(pga[mapped].pg));
2238 LASSERT(mapped == 0 ||
2239 pga[mapped].disk_offset > pga[mapped - 1].disk_offset);
2241 nioptr->offset = pga[mapped].disk_offset;
2242 nioptr->len = pga[mapped].count;
2243 nioptr->flags = pga[mapped].flag;
2246 size[1] = page_count * sizeof(*nioptr);
2247 request->rq_replen = lustre_msg_size(2, size);
2249 rc = ptlrpc_queue_wait(request);
2253 swab = lustre_msg_swabbed (request->rq_repmsg);
2254 LASSERT_REPSWAB (request, 1);
2255 nioptr = lustre_msg_buf(request->rq_repmsg, 1, size[1]);
2257 CERROR("absent/short niobuf array\n");
2258 GOTO(out_req, rc = -EPROTO);
2262 for (mapped = 0; mapped < page_count; mapped++, nioptr++) {
2263 struct page *page = pga[mapped].pg;
2264 struct buffer_head *bh;
2268 lustre_swab_niobuf_remote (nioptr);
2270 /* got san device associated */
2271 LASSERT(exp->exp_obd != NULL);
2272 dev = exp->exp_obd->u.cli.cl_sandev;
2274 if (!page->buffers) {
2275 create_empty_buffers(page, dev, PAGE_SIZE);
2278 LASSERT(!test_bit(BH_New, &page->buffers->b_state));
2279 LASSERT(test_bit(BH_Mapped, &page->buffers->b_state));
2280 LASSERT(page->buffers->b_blocknr ==
2281 (unsigned long)nioptr->offset);
2287 /* if buffer locked, wait it's io completion */
2288 if (test_bit(BH_Lock, &bh->b_state))
2291 clear_bit(BH_New, &bh->b_state);
2292 set_bit(BH_Mapped, &bh->b_state);
2294 /* override the block nr */
2295 bh->b_blocknr = (unsigned long)nioptr->offset;
2297 /* we are about to write it, so set it
2299 * page lock should garentee no race condition here */
2300 set_bit(BH_Uptodate, &bh->b_state);
2301 set_bit(BH_Dirty, &bh->b_state);
2303 ll_rw_block(WRITE, 1, &bh);
2305 /* must do syncronous write here */
2307 if (!buffer_uptodate(bh) || test_bit(BH_Dirty, &bh->b_state)) {
2315 ptlrpc_req_finished(request);
2319 static int sanosc_brw(int cmd, struct obd_export *exp, struct obdo *oa,
2320 struct lov_stripe_md *lsm, obd_count page_count,
2321 struct brw_page *pga, struct obd_trans_info *oti)
2325 while (page_count) {
2326 obd_count pages_per_brw;
2329 if (page_count > PTLRPC_MAX_BRW_PAGES)
2330 pages_per_brw = PTLRPC_MAX_BRW_PAGES;
2332 pages_per_brw = page_count;
2334 if (cmd & OBD_BRW_WRITE)
2335 rc = sanosc_brw_write(exp, oa, lsm, pages_per_brw,pga);
2337 rc = sanosc_brw_read(exp, oa, lsm, pages_per_brw, pga);
2342 page_count -= pages_per_brw;
2343 pga += pages_per_brw;
2350 static void osc_set_data_with_check(struct lustre_handle *lockh, void *data)
2352 struct ldlm_lock *lock = ldlm_handle2lock(lockh);
2355 CERROR("lockh %p, data %p - client evicted?\n", lockh, data);
2359 l_lock(&lock->l_resource->lr_namespace->ns_lock);
2361 if (lock->l_ast_data && lock->l_ast_data != data) {
2362 struct inode *new_inode = data;
2363 struct inode *old_inode = lock->l_ast_data;
2364 if (!(old_inode->i_state & I_FREEING))
2365 LDLM_ERROR(lock, "inconsistent l_ast_data found");
2366 LASSERTF(old_inode->i_state & I_FREEING,
2367 "Found existing inode %p/%lu/%u state %lu in lock: "
2368 "setting data to %p/%lu/%u\n", old_inode,
2369 old_inode->i_ino, old_inode->i_generation,
2371 new_inode, new_inode->i_ino, new_inode->i_generation);
2374 lock->l_ast_data = data;
2375 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
2376 LDLM_LOCK_PUT(lock);
2379 static int osc_change_cbdata(struct obd_export *exp, struct lov_stripe_md *lsm,
2380 ldlm_iterator_t replace, void *data)
2382 struct ldlm_res_id res_id = { .name = {0} };
2383 struct obd_device *obd = class_exp2obd(exp);
2385 res_id.name[0] = lsm->lsm_object_id;
2386 res_id.name[2] = lsm->lsm_object_gr;
2387 ldlm_change_cbdata(obd->obd_namespace, &res_id, replace, data);
2391 static int osc_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm,
2392 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
2393 int *flags, void *bl_cb, void *cp_cb, void *gl_cb,
2394 void *data, __u32 lvb_len, void *lvb_swabber,
2395 struct lustre_handle *lockh)
2397 struct obd_device *obd = exp->exp_obd;
2398 struct ldlm_res_id res_id = { .name = {0} };
2400 struct ldlm_reply *rep;
2401 struct ptlrpc_request *req = NULL;
2405 res_id.name[0] = lsm->lsm_object_id;
2406 res_id.name[2] = lsm->lsm_object_gr;
2408 /* Filesystem lock extents are extended to page boundaries so that
2409 * dealing with the page cache is a little smoother. */
2410 policy->l_extent.start -= policy->l_extent.start & ~PAGE_MASK;
2411 policy->l_extent.end |= ~PAGE_MASK;
2413 if (lsm->lsm_oinfo->loi_kms_valid == 0)
2416 /* Next, search for already existing extent locks that will cover us */
2417 rc = ldlm_lock_match(obd->obd_namespace, 0, &res_id, type, policy, mode,
2420 osc_set_data_with_check(lockh, data);
2421 if (*flags & LDLM_FL_HAS_INTENT) {
2422 /* I would like to be able to ASSERT here that rss <=
2423 * kms, but I can't, for reasons which are explained in
2426 /* We already have a lock, and it's referenced */
2430 /* If we're trying to read, we also search for an existing PW lock. The
2431 * VFS and page cache already protect us locally, so lots of readers/
2432 * writers can share a single PW lock.
2434 * There are problems with conversion deadlocks, so instead of
2435 * converting a read lock to a write lock, we'll just enqueue a new
2438 * At some point we should cancel the read lock instead of making them
2439 * send us a blocking callback, but there are problems with canceling
2440 * locks out from other users right now, too. */
2442 if (mode == LCK_PR) {
2443 rc = ldlm_lock_match(obd->obd_namespace, 0, &res_id, type,
2444 policy, LCK_PW, lockh);
2446 /* FIXME: This is not incredibly elegant, but it might
2447 * be more elegant than adding another parameter to
2448 * lock_match. I want a second opinion. */
2449 ldlm_lock_addref(lockh, LCK_PR);
2450 ldlm_lock_decref(lockh, LCK_PW);
2451 osc_set_data_with_check(lockh, data);
2455 if (mode == LCK_PW) {
2456 rc = ldlm_lock_match(obd->obd_namespace, 0, &res_id, type,
2457 policy, LCK_PR, lockh);
2459 rc = ldlm_cli_convert(lockh, mode, flags);
2461 /* Update readers/writers accounting */
2462 ldlm_lock_addref(lockh, LCK_PW);
2463 ldlm_lock_decref(lockh, LCK_PR);
2464 osc_set_data_with_check(lockh, data);
2467 /* If the conversion failed, we need to drop refcount
2468 on matched lock before we get new one */
2469 /* XXX Won't it save us some efforts if we cancel PR
2470 lock here? We are going to take PW lock anyway and it
2471 will invalidate PR lock */
2472 ldlm_lock_decref(lockh, LCK_PR);
2473 if (rc != EDEADLOCK) {
2479 if (mode == LCK_PW) {
2480 rc = ldlm_lock_match(obd->obd_namespace, 0, &res_id, type,
2481 policy, LCK_PR, lockh);
2483 rc = ldlm_cli_convert(lockh, mode, flags);
2485 /* Update readers/writers accounting */
2486 ldlm_lock_addref(lockh, LCK_PW);
2487 ldlm_lock_decref(lockh, LCK_PR);
2488 osc_set_data_with_check(lockh, data);
2491 /* If the conversion failed, we need to drop refcount
2492 on matched lock before we get new one */
2493 /* XXX Won't it save us some efforts if we cancel PR
2494 lock here? We are going to take PW lock anyway and it
2495 will invalidate PR lock */
2496 ldlm_lock_decref(lockh, LCK_PR);
2497 if (rc != EDEADLOCK) {
2504 if (*flags & LDLM_FL_HAS_INTENT) {
2505 int size[2] = {0, sizeof(struct ldlm_request)};
2507 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_DLM_VERSION,
2508 LDLM_ENQUEUE, 2, size, NULL);
2512 size[0] = sizeof(*rep);
2513 size[1] = sizeof(lvb);
2514 req->rq_replen = lustre_msg_size(2, size);
2516 rc = ldlm_cli_enqueue(exp, req, obd->obd_namespace, res_id, type,
2517 policy, mode, flags, bl_cb, cp_cb, gl_cb, data,
2518 &lvb, sizeof(lvb), lustre_swab_ost_lvb, lockh);
2520 if (rc == ELDLM_LOCK_ABORTED) {
2521 /* swabbed by ldlm_cli_enqueue() */
2522 LASSERT_REPSWABBED(req, 0);
2523 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep));
2524 LASSERT(rep != NULL);
2525 if (rep->lock_policy_res1)
2526 rc = rep->lock_policy_res1;
2528 ptlrpc_req_finished(req);
2531 if ((*flags & LDLM_FL_HAS_INTENT && rc == ELDLM_LOCK_ABORTED) || !rc) {
2532 CDEBUG(D_INODE, "received kms == "LPU64", blocks == "LPU64"\n",
2533 lvb.lvb_size, lvb.lvb_blocks);
2534 lsm->lsm_oinfo->loi_rss = lvb.lvb_size;
2535 lsm->lsm_oinfo->loi_blocks = lvb.lvb_blocks;
2541 static int osc_match(struct obd_export *exp, struct lov_stripe_md *lsm,
2542 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
2543 int *flags, void *data, struct lustre_handle *lockh)
2545 struct ldlm_res_id res_id = { .name = {0} };
2546 struct obd_device *obd = exp->exp_obd;
2550 res_id.name[0] = lsm->lsm_object_id;
2551 res_id.name[2] = lsm->lsm_object_gr;
2553 OBD_FAIL_RETURN(OBD_FAIL_OSC_MATCH, -EIO);
2555 /* Filesystem lock extents are extended to page boundaries so that
2556 * dealing with the page cache is a little smoother */
2557 policy->l_extent.start -= policy->l_extent.start & ~PAGE_MASK;
2558 policy->l_extent.end |= ~PAGE_MASK;
2560 /* Next, search for already existing extent locks that will cover us */
2561 rc = ldlm_lock_match(obd->obd_namespace, *flags, &res_id, type,
2562 policy, mode, lockh);
2564 // if (!(*flags & LDLM_FL_TEST_LOCK))
2565 osc_set_data_with_check(lockh, data);
2568 /* If we're trying to read, we also search for an existing PW lock. The
2569 * VFS and page cache already protect us locally, so lots of readers/
2570 * writers can share a single PW lock. */
2571 if (mode == LCK_PR) {
2572 rc = ldlm_lock_match(obd->obd_namespace, *flags, &res_id, type,
2573 policy, LCK_PW, lockh);
2574 if (rc == 1 && !(*flags & LDLM_FL_TEST_LOCK)) {
2575 /* FIXME: This is not incredibly elegant, but it might
2576 * be more elegant than adding another parameter to
2577 * lock_match. I want a second opinion. */
2578 osc_set_data_with_check(lockh, data);
2579 ldlm_lock_addref(lockh, LCK_PR);
2580 ldlm_lock_decref(lockh, LCK_PW);
2586 static int osc_cancel(struct obd_export *exp, struct lov_stripe_md *md,
2587 __u32 mode, struct lustre_handle *lockh)
2591 if (mode == LCK_GROUP)
2592 ldlm_lock_decref_and_cancel(lockh, mode);
2594 ldlm_lock_decref(lockh, mode);
2599 static int osc_cancel_unused(struct obd_export *exp,
2600 struct lov_stripe_md *lsm, int flags, void *opaque)
2602 struct obd_device *obd = class_exp2obd(exp);
2603 struct ldlm_res_id res_id = { .name = {0} }, *resp = NULL;
2606 res_id.name[0] = lsm->lsm_object_id;
2607 res_id.name[2] = lsm->lsm_object_gr;
2611 return ldlm_cli_cancel_unused(obd->obd_namespace, resp, flags, opaque);
2614 static int osc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
2615 unsigned long max_age)
2617 struct obd_statfs *msfs;
2618 struct ptlrpc_request *request;
2619 int rc, size = sizeof(*osfs);
2622 /* We could possibly pass max_age in the request (as an absolute
2623 * timestamp or a "seconds.usec ago") so the target can avoid doing
2624 * extra calls into the filesystem if that isn't necessary (e.g.
2625 * during mount that would help a bit). Having relative timestamps
2626 * is not so great if request processing is slow, while absolute
2627 * timestamps are not ideal because they need time synchronization. */
2628 request = ptlrpc_prep_req(obd->u.cli.cl_import, LUSTRE_OBD_VERSION,
2629 OST_STATFS, 0, NULL, NULL);
2633 request->rq_replen = lustre_msg_size(1, &size);
2634 request->rq_request_portal = OST_CREATE_PORTAL; //XXX FIXME bug 249
2636 rc = ptlrpc_queue_wait(request);
2640 msfs = lustre_swab_repbuf(request, 0, sizeof(*msfs),
2641 lustre_swab_obd_statfs);
2643 CERROR("Can't unpack obd_statfs\n");
2644 GOTO(out, rc = -EPROTO);
2647 memcpy(osfs, msfs, sizeof(*osfs));
2651 ptlrpc_req_finished(request);
2655 /* Retrieve object striping information.
2657 * @lmmu is a pointer to an in-core struct with lmm_ost_count indicating
2658 * the maximum number of OST indices which will fit in the user buffer.
2659 * lmm_magic must be LOV_MAGIC (we only use 1 slot here).
2661 static int osc_getstripe(struct lov_stripe_md *lsm, struct lov_user_md *lump)
2663 struct lov_user_md lum, *lumk;
2670 rc = copy_from_user(&lum, lump, sizeof(lum));
2674 if (lum.lmm_magic != LOV_USER_MAGIC)
2677 if (lum.lmm_stripe_count > 0) {
2678 lum_size = sizeof(lum) + sizeof(lum.lmm_objects[0]);
2679 OBD_ALLOC(lumk, lum_size);
2683 lumk->lmm_objects[0].l_object_id = lsm->lsm_object_id;
2684 lumk->lmm_objects[0].l_object_gr = lsm->lsm_object_gr;
2686 lum_size = sizeof(lum);
2690 lumk->lmm_object_id = lsm->lsm_object_id;
2691 lumk->lmm_object_gr = lsm->lsm_object_gr;
2692 lumk->lmm_stripe_count = 1;
2694 if (copy_to_user(lump, lumk, lum_size))
2698 OBD_FREE(lumk, lum_size);
2703 static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2704 void *karg, void *uarg)
2706 struct obd_device *obd = exp->exp_obd;
2707 struct obd_ioctl_data *data = karg;
2711 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
2714 if (!try_module_get(THIS_MODULE)) {
2715 CERROR("Can't get module. Is it alive?");
2720 case OBD_IOC_LOV_GET_CONFIG: {
2722 struct lov_desc *desc;
2723 struct obd_uuid uuid;
2727 if (obd_ioctl_getdata(&buf, &len, (void *)uarg))
2728 GOTO(out, err = -EINVAL);
2730 data = (struct obd_ioctl_data *)buf;
2732 if (sizeof(*desc) > data->ioc_inllen1) {
2734 GOTO(out, err = -EINVAL);
2737 if (data->ioc_inllen2 < sizeof(uuid)) {
2739 GOTO(out, err = -EINVAL);
2742 if (data->ioc_inllen3 < sizeof(__u32)) {
2744 GOTO(out, err = -EINVAL);
2747 desc = (struct lov_desc *)data->ioc_inlbuf1;
2748 desc->ld_tgt_count = 1;
2749 desc->ld_active_tgt_count = 1;
2750 desc->ld_default_stripe_count = 1;
2751 desc->ld_default_stripe_size = 0;
2752 desc->ld_default_stripe_offset = 0;
2753 desc->ld_pattern = 0;
2754 memcpy(&desc->ld_uuid, &obd->obd_uuid, sizeof(uuid));
2755 memcpy(data->ioc_inlbuf2, &obd->obd_uuid, sizeof(uuid));
2756 *((__u32 *)data->ioc_inlbuf3) = 1;
2758 err = copy_to_user((void *)uarg, buf, len);
2761 obd_ioctl_freedata(buf, len);
2764 case LL_IOC_LOV_SETSTRIPE:
2765 err = obd_alloc_memmd(exp, karg);
2769 case LL_IOC_LOV_GETSTRIPE:
2770 err = osc_getstripe(karg, uarg);
2772 case OBD_IOC_CLIENT_RECOVER:
2773 err = ptlrpc_recover_import(obd->u.cli.cl_import,
2778 case IOC_OSC_SET_ACTIVE:
2779 err = ptlrpc_set_import_active(obd->u.cli.cl_import,
2782 case IOC_OSC_CTL_RECOVERY:
2783 err = ptlrpc_import_control_recovery(obd->u.cli.cl_import,
2787 CDEBUG(D_INODE, "unrecognised ioctl %#x by %s\n", cmd, current->comm);
2788 GOTO(out, err = -ENOTTY);
2791 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
2794 module_put(THIS_MODULE);
2799 static int osc_get_info(struct obd_export *exp, obd_count keylen,
2800 void *key, __u32 *vallen, void *val)
2803 if (!vallen || !val)
2806 if (keylen > strlen("lock_to_stripe") &&
2807 strcmp(key, "lock_to_stripe") == 0) {
2808 __u32 *stripe = val;
2809 *vallen = sizeof(*stripe);
2812 } else if (keylen >= strlen("last_id") && strcmp(key, "last_id") == 0) {
2813 struct ptlrpc_request *req;
2815 char *bufs[1] = {key};
2817 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OBD_VERSION,
2818 OST_GET_INFO, 1, &keylen, bufs);
2822 req->rq_replen = lustre_msg_size(1, vallen);
2823 rc = ptlrpc_queue_wait(req);
2827 reply = lustre_swab_repbuf(req, 0, sizeof(*reply),
2828 lustre_swab_ost_last_id);
2829 if (reply == NULL) {
2830 CERROR("Can't unpack OST last ID\n");
2831 GOTO(out, rc = -EPROTO);
2833 *((obd_id *)val) = *reply;
2835 ptlrpc_req_finished(req);
2841 static int osc_set_info(struct obd_export *exp, obd_count keylen,
2842 void *key, obd_count vallen, void *val)
2844 struct obd_device *obd = exp->exp_obd;
2845 struct obd_import *imp = class_exp2cliimp(exp);
2846 struct llog_ctxt *ctxt;
2850 if (keylen == strlen("next_id") &&
2851 memcmp(key, "next_id", strlen("next_id")) == 0) {
2852 if (vallen != sizeof(obd_id))
2854 obd->u.cli.cl_oscc.oscc_next_id = *((obd_id*)val) + 1;
2855 CDEBUG(D_HA, "%s: set oscc_next_id = "LPU64"\n",
2856 exp->exp_obd->obd_name,
2857 obd->u.cli.cl_oscc.oscc_next_id);
2862 if (keylen == strlen("growth_count") &&
2863 memcmp(key, "growth_count", strlen("growth_count")) == 0) {
2864 if (vallen != sizeof(int))
2866 obd->u.cli.cl_oscc.oscc_max_grow_count = *((int*)val);
2870 if (keylen == strlen("unlinked") &&
2871 memcmp(key, "unlinked", keylen) == 0) {
2872 struct osc_creator *oscc = &obd->u.cli.cl_oscc;
2873 spin_lock(&oscc->oscc_lock);
2874 oscc->oscc_flags &= ~OSCC_FLAG_NOSPC;
2875 spin_unlock(&oscc->oscc_lock);
2878 if (keylen == strlen("unrecovery") &&
2879 memcmp(key, "unrecovery", keylen) == 0) {
2880 struct osc_creator *oscc = &obd->u.cli.cl_oscc;
2881 spin_lock(&oscc->oscc_lock);
2882 oscc->oscc_flags &= ~OSCC_FLAG_RECOVERING;
2883 spin_unlock(&oscc->oscc_lock);
2886 if (keylen == strlen("initial_recov") &&
2887 memcmp(key, "initial_recov", strlen("initial_recov")) == 0) {
2888 struct obd_import *imp = exp->exp_obd->u.cli.cl_import;
2889 if (vallen != sizeof(int))
2891 imp->imp_initial_recov = *(int *)val;
2892 CDEBUG(D_HA, "%s: set imp_no_init_recov = %d\n",
2893 exp->exp_obd->obd_name,
2894 imp->imp_initial_recov);
2898 if (keylen == strlen("async") && memcmp(key, "async", keylen) == 0) {
2899 struct client_obd *cl = &obd->u.cli;
2900 if (vallen != sizeof(int))
2902 cl->cl_async = *(int *)val;
2903 CDEBUG(D_HA, "%s: set async = %d\n",
2904 obd->obd_name, cl->cl_async);
2908 if (keylen == strlen("sec") && memcmp(key, "sec", keylen) == 0) {
2909 struct client_obd *cli = &exp->exp_obd->u.cli;
2911 if (vallen == strlen("null") &&
2912 memcmp(val, "null", vallen) == 0) {
2913 cli->cl_sec_flavor = PTLRPC_SEC_NULL;
2914 cli->cl_sec_subflavor = 0;
2917 if (vallen == strlen("krb5i") &&
2918 memcmp(val, "krb5i", vallen) == 0) {
2919 cli->cl_sec_flavor = PTLRPC_SEC_GSS;
2920 cli->cl_sec_subflavor = PTLRPC_SEC_GSS_KRB5I;
2923 if (vallen == strlen("krb5p") &&
2924 memcmp(val, "krb5p", vallen) == 0) {
2925 cli->cl_sec_flavor = PTLRPC_SEC_GSS;
2926 cli->cl_sec_subflavor = PTLRPC_SEC_GSS_KRB5P;
2929 CERROR("unrecognized security type %s\n", (char*) val);
2933 if (keylen < strlen("mds_conn") || memcmp(key, "mds_conn", keylen) != 0)
2936 ctxt = llog_get_context(&exp->exp_obd->obd_llogs, LLOG_UNLINK_ORIG_CTXT);
2939 rc = llog_initiator_connect(ctxt);
2941 CERROR("cannot establish the connect for ctxt %p: %d\n",
2945 imp->imp_server_timeout = 1;
2946 CDEBUG(D_HA, "pinging OST %s\n", imp->imp_target_uuid.uuid);
2947 imp->imp_pingable = 1;
2953 static struct llog_operations osc_size_repl_logops = {
2954 lop_cancel: llog_obd_repl_cancel
2957 static struct llog_operations osc_unlink_orig_logops;
2958 static int osc_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
2959 struct obd_device *tgt, int count,
2960 struct llog_catid *catid)
2965 osc_unlink_orig_logops = llog_lvfs_ops;
2966 osc_unlink_orig_logops.lop_setup = llog_obd_origin_setup;
2967 osc_unlink_orig_logops.lop_cleanup = llog_catalog_cleanup;
2968 osc_unlink_orig_logops.lop_add = llog_catalog_add;
2969 osc_unlink_orig_logops.lop_connect = llog_origin_connect;
2971 rc = obd_llog_setup(obd, llogs, LLOG_UNLINK_ORIG_CTXT, tgt, count,
2972 &catid->lci_logid, &osc_unlink_orig_logops);
2976 rc = obd_llog_setup(obd, llogs, LLOG_SIZE_REPL_CTXT, tgt, count, NULL,
2977 &osc_size_repl_logops);
2981 static int osc_llog_finish(struct obd_device *obd,
2982 struct obd_llogs *llogs, int count)
2987 rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_UNLINK_ORIG_CTXT));
2991 rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_SIZE_REPL_CTXT));
2996 static int osc_connect(struct lustre_handle *exph,
2997 struct obd_device *obd, struct obd_uuid *cluuid,
2998 struct obd_connect_data *data,
2999 unsigned long connect_flags)
3003 rc = client_connect_import(exph, obd, cluuid, data, connect_flags);
3007 static int osc_disconnect(struct obd_export *exp, unsigned long flags)
3009 struct obd_device *obd = class_exp2obd(exp);
3010 struct llog_ctxt *ctxt;
3014 ctxt = llog_get_context(&obd->obd_llogs, LLOG_SIZE_REPL_CTXT);
3015 if (obd->u.cli.cl_conn_count == 1)
3016 /* flush any remaining cancel messages out to the target */
3017 llog_sync(ctxt, exp);
3019 rc = client_disconnect_export(exp, flags);
3023 static int osc_import_event(struct obd_device *obd,
3024 struct obd_import *imp,
3025 enum obd_import_event event)
3027 struct client_obd *cli;
3030 LASSERT(imp->imp_obd == obd);
3033 case IMP_EVENT_DISCON: {
3034 /* Only do this on the MDS OSC's */
3035 if (imp->imp_server_timeout) {
3036 struct osc_creator *oscc = &obd->u.cli.cl_oscc;
3038 spin_lock(&oscc->oscc_lock);
3039 oscc->oscc_flags |= OSCC_FLAG_RECOVERING;
3040 spin_unlock(&oscc->oscc_lock);
3044 case IMP_EVENT_INACTIVE: {
3045 if (obd->obd_observer)
3046 rc = obd_notify(obd->obd_observer, obd, 0, 0);
3049 case IMP_EVENT_INVALIDATE: {
3050 struct ldlm_namespace *ns = obd->obd_namespace;
3054 spin_lock(&cli->cl_loi_list_lock);
3055 cli->cl_avail_grant = 0;
3056 cli->cl_lost_grant = 0;
3057 /* all pages go to failing rpcs due to the invalid import */
3058 osc_check_rpcs(cli);
3059 spin_unlock(&cli->cl_loi_list_lock);
3061 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
3065 case IMP_EVENT_ACTIVE: {
3066 /* Only do this on the MDS OSC's */
3067 if (imp->imp_server_timeout) {
3068 struct osc_creator *oscc = &obd->u.cli.cl_oscc;
3070 spin_lock(&oscc->oscc_lock);
3071 oscc->oscc_flags &= ~OSCC_FLAG_NOSPC;
3072 spin_unlock(&oscc->oscc_lock);
3075 if (obd->obd_observer)
3076 rc = obd_notify(obd->obd_observer, obd, 1, 0);
3080 CERROR("Unknown import event %d\n", event);
3086 static int osc_attach(struct obd_device *dev, obd_count len, void *data)
3088 struct lprocfs_static_vars lvars;
3092 lprocfs_init_vars(osc,&lvars);
3093 rc = lprocfs_obd_attach(dev, lvars.obd_vars);
3097 rc = lproc_osc_attach_seqstat(dev);
3099 lprocfs_obd_detach(dev);
3103 ptlrpc_lprocfs_register_obd(dev);
3107 static int osc_detach(struct obd_device *dev)
3109 ptlrpc_lprocfs_unregister_obd(dev);
3110 return lprocfs_obd_detach(dev);
3113 static int osc_setup(struct obd_device *obd, obd_count len, void *buf)
3117 rc = ptlrpcd_addref();
3121 rc = client_obd_setup(obd, len, buf);
3130 static int osc_cleanup(struct obd_device *obd, int flags)
3132 struct osc_creator *oscc = &obd->u.cli.cl_oscc;
3135 rc = ldlm_cli_cancel_unused(obd->obd_namespace, NULL,
3136 LDLM_FL_CONFIG_CHANGE, NULL);
3140 spin_lock(&oscc->oscc_lock);
3141 oscc->oscc_flags &= ~OSCC_FLAG_RECOVERING;
3142 oscc->oscc_flags |= OSCC_FLAG_EXITING;
3143 spin_unlock(&oscc->oscc_lock);
3145 rc = client_obd_cleanup(obd, flags);
3150 struct obd_ops osc_obd_ops = {
3151 .o_owner = THIS_MODULE,
3152 .o_attach = osc_attach,
3153 .o_detach = osc_detach,
3154 .o_setup = osc_setup,
3155 .o_cleanup = osc_cleanup,
3156 .o_add_conn = client_import_add_conn,
3157 .o_del_conn = client_import_del_conn,
3158 .o_connect = osc_connect,
3159 .o_disconnect = osc_disconnect,
3160 .o_statfs = osc_statfs,
3161 .o_packmd = osc_packmd,
3162 .o_unpackmd = osc_unpackmd,
3163 .o_create = osc_create,
3164 .o_destroy = osc_destroy,
3165 .o_getattr = osc_getattr,
3166 .o_getattr_async = osc_getattr_async,
3167 .o_setattr = osc_setattr,
3169 .o_brw_async = osc_brw_async,
3170 .o_prep_async_page = osc_prep_async_page,
3171 .o_queue_async_io = osc_queue_async_io,
3172 .o_set_async_flags = osc_set_async_flags,
3173 .o_queue_group_io = osc_queue_group_io,
3174 .o_trigger_group_io = osc_trigger_group_io,
3175 .o_teardown_async_page = osc_teardown_async_page,
3176 .o_punch = osc_punch,
3178 .o_enqueue = osc_enqueue,
3179 .o_match = osc_match,
3180 .o_change_cbdata = osc_change_cbdata,
3181 .o_cancel = osc_cancel,
3182 .o_cancel_unused = osc_cancel_unused,
3183 .o_iocontrol = osc_iocontrol,
3184 .o_get_info = osc_get_info,
3185 .o_set_info = osc_set_info,
3186 .o_import_event = osc_import_event,
3187 .o_llog_init = osc_llog_init,
3188 .o_llog_finish = osc_llog_finish,
3191 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
3192 struct obd_ops sanosc_obd_ops = {
3193 .o_owner = THIS_MODULE,
3194 .o_attach = osc_attach,
3195 .o_detach = osc_detach,
3196 .o_cleanup = client_obd_cleanup,
3197 .o_add_conn = client_import_add_conn,
3198 .o_del_conn = client_import_del_conn,
3199 .o_connect = osc_connect,
3200 .o_disconnect = client_disconnect_export,
3201 .o_statfs = osc_statfs,
3202 .o_packmd = osc_packmd,
3203 .o_unpackmd = osc_unpackmd,
3204 .o_create = osc_real_create,
3205 .o_destroy = osc_destroy,
3206 .o_getattr = osc_getattr,
3207 .o_getattr_async = osc_getattr_async,
3208 .o_setattr = osc_setattr,
3209 .o_setup = client_sanobd_setup,
3210 .o_brw = sanosc_brw,
3211 .o_punch = osc_punch,
3213 .o_enqueue = osc_enqueue,
3214 .o_match = osc_match,
3215 .o_change_cbdata = osc_change_cbdata,
3216 .o_cancel = osc_cancel,
3217 .o_cancel_unused = osc_cancel_unused,
3218 .o_iocontrol = osc_iocontrol,
3219 .o_import_event = osc_import_event,
3220 .o_llog_init = osc_llog_init,
3221 .o_llog_finish = osc_llog_finish,
3225 int __init osc_init(void)
3227 struct lprocfs_static_vars lvars;
3228 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
3229 struct lprocfs_static_vars sanlvars;
3234 lprocfs_init_vars(osc, &lvars);
3235 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
3236 lprocfs_init_vars(osc, &sanlvars);
3239 rc = class_register_type(&osc_obd_ops, NULL, lvars.module_vars,
3244 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
3245 rc = class_register_type(&sanosc_obd_ops, NULL, sanlvars.module_vars,
3246 LUSTRE_SANOSC_NAME);
3248 class_unregister_type(LUSTRE_OSC_NAME);
3255 static void /*__exit*/ osc_exit(void)
3257 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
3258 class_unregister_type(LUSTRE_SANOSC_NAME);
3260 class_unregister_type(LUSTRE_OSC_NAME);
3263 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
3264 MODULE_DESCRIPTION("Lustre Object Storage Client (OSC)");
3265 MODULE_LICENSE("GPL");
3267 module_init(osc_init);
3268 module_exit(osc_exit);