Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / lustre / ptlrpc / pers.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #define DEBUG_SUBSYSTEM S_RPC
38 #ifndef __KERNEL__
39 #include <errno.h>
40 #include <signal.h>
41 #include <liblustre.h>
42 #endif
43
44 #include <obd_support.h>
45 #include <obd_class.h>
46 #include <lustre_lib.h>
47 #include <lustre_ha.h>
48 #include <lustre_import.h>
49
50 #include "ptlrpc_internal.h"
51
52 #ifdef __KERNEL__
53
54 void ptlrpc_fill_bulk_md (lnet_md_t *md, struct ptlrpc_bulk_desc *desc)
55 {
56         LASSERT (desc->bd_iov_count <= PTLRPC_MAX_BRW_PAGES);
57         LASSERT (!(md->options & (LNET_MD_IOVEC | LNET_MD_KIOV | LNET_MD_PHYS)));
58
59         md->options |= LNET_MD_KIOV;
60         md->start = &desc->bd_iov[0];
61         md->length = desc->bd_iov_count;
62 }
63
64 void ptlrpc_add_bulk_page(struct ptlrpc_bulk_desc *desc, cfs_page_t *page,
65                           int pageoffset, int len)
66 {
67         lnet_kiov_t *kiov = &desc->bd_iov[desc->bd_iov_count];
68
69         kiov->kiov_page = page;
70         kiov->kiov_offset = pageoffset;
71         kiov->kiov_len = len;
72
73         desc->bd_iov_count++;
74 }
75
76 void ptl_rpc_wipe_bulk_pages(struct ptlrpc_bulk_desc *desc)
77 {
78         int i;
79         
80         for (i = 0; i < desc->bd_iov_count ; i++) {
81                 lnet_kiov_t *kiov = &desc->bd_iov[i];
82                 memset(cfs_kmap(kiov->kiov_page)+kiov->kiov_offset, 0xab,
83                        kiov->kiov_len);
84                 cfs_kunmap(kiov->kiov_page);
85         }
86 }
87
88 #else /* !__KERNEL__ */
89
90 void ptlrpc_fill_bulk_md(lnet_md_t *md, struct ptlrpc_bulk_desc *desc)
91 {
92         LASSERT (!(md->options & (LNET_MD_IOVEC | LNET_MD_KIOV | LNET_MD_PHYS)));
93         if (desc->bd_iov_count == 1) {
94                 md->start = desc->bd_iov[0].iov_base;
95                 md->length = desc->bd_iov[0].iov_len;
96                 return;
97         }
98         
99         md->options |= LNET_MD_IOVEC;
100         md->start = &desc->bd_iov[0];
101         md->length = desc->bd_iov_count;
102 }
103
104 static int can_merge_iovs(lnet_md_iovec_t *existing, lnet_md_iovec_t *candidate)
105 {
106         if (existing->iov_base + existing->iov_len == candidate->iov_base) 
107                 return 1;
108 #if 0
109         /* Enable this section to provide earlier evidence of fragmented bulk */
110         CERROR("Can't merge iovs %p for %x, %p for %x\n",
111                existing->iov_base, existing->iov_len,
112                candidate->iov_base, candidate->iov_len);
113 #endif
114         return 0;
115 }
116
117 void ptlrpc_add_bulk_page(struct ptlrpc_bulk_desc *desc, cfs_page_t *page, 
118                           int pageoffset, int len)
119 {
120         lnet_md_iovec_t *iov = &desc->bd_iov[desc->bd_iov_count];
121
122         iov->iov_base = page->addr + pageoffset;
123         iov->iov_len = len;
124
125         if (desc->bd_iov_count > 0 && can_merge_iovs(iov - 1, iov)) {
126                 (iov - 1)->iov_len += len;
127         } else {
128                 desc->bd_iov_count++;
129         }
130 }
131
132 void ptl_rpc_wipe_bulk_pages(struct ptlrpc_bulk_desc *desc)
133 {
134         int i;
135
136         for(i = 0; i < desc->bd_iov_count; i++) {
137                 lnet_md_iovec_t *iov = &desc->bd_iov[i];
138
139                 memset(iov->iov_base, 0xab, iov->iov_len);
140         }
141 }
142 #endif /* !__KERNEL__ */