Whamcloud - gitweb
- landed b_hd_cray_merge3
[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  *  Copyright (c) 2004 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #define DEBUG_SUBSYSTEM S_RPC
23 #ifndef __KERNEL__
24 #include <errno.h>
25 #include <signal.h>
26 #include <liblustre.h>
27 #endif
28
29 #include <linux/obd_support.h>
30 #include <linux/obd_class.h>
31 #include <linux/lustre_lib.h>
32 #include <linux/lustre_ha.h>
33 #include <linux/lustre_import.h>
34
35 #include "ptlrpc_internal.h"
36
37 #ifdef __KERNEL__
38 #if !CRAY_PORTALS
39
40 void ptlrpc_fill_bulk_md (ptl_md_t *md, struct ptlrpc_bulk_desc *desc)
41 {
42         LASSERT (desc->bd_iov_count <= PTLRPC_MAX_BRW_PAGES);
43         LASSERT (!(md->options & (PTL_MD_IOVEC | PTL_MD_KIOV | PTL_MD_PHYS)));
44
45         md->options |= PTL_MD_KIOV;
46         md->start = &desc->bd_iov[0];
47         md->length = desc->bd_iov_count;
48 }
49
50 void ptlrpc_add_bulk_page(struct ptlrpc_bulk_desc *desc, struct page *page,
51                           int pageoffset, int len)
52 {
53         ptl_kiov_t *kiov = &desc->bd_iov[desc->bd_iov_count];
54
55         kiov->kiov_page = page;
56         kiov->kiov_offset = pageoffset;
57         kiov->kiov_len = len;
58
59         desc->bd_iov_count++;
60 }
61
62 #else  /* CRAY_PORTALS */
63 #ifdef PTL_MD_KIOV
64 #error "Conflicting compilation directives"
65 #endif
66
67 void ptlrpc_fill_bulk_md (ptl_md_t *md, struct ptlrpc_bulk_desc *desc)
68 {
69         LASSERT (desc->bd_iov_count <= PTLRPC_MAX_BRW_PAGES);
70         LASSERT (!(md->options & (PTL_MD_IOVEC | PTL_MD_PHYS)));
71         
72         md->options |= (PTL_MD_IOVEC | PTL_MD_PHYS);
73         md->start = &desc->bd_iov[0];
74         md->length = desc->bd_iov_count;
75 }
76
77 void ptlrpc_add_bulk_page(struct ptlrpc_bulk_desc *desc, struct page *page,
78                           int pageoffset, int len)
79 {
80         ptl_md_iovec_t *iov = &desc->bd_iov[desc->bd_iov_count];
81
82         /* Should get a compiler warning if sizeof(physaddr) > sizeof(void *) */
83         iov->iov_base = (void *)(page_to_phys(page) + pageoffset);
84         iov->iov_len = len;
85
86         desc->bd_iov_count++;
87 }
88
89 #endif /* CRAY_PORTALS */
90 #else /* !__KERNEL__ */
91
92 void ptlrpc_fill_bulk_md(ptl_md_t *md, struct ptlrpc_bulk_desc *desc)
93 {
94 #if CRAY_PORTALS
95         LASSERT (!(md->options & (PTL_MD_IOVEC | PTL_MD_PHYS)));
96         LASSERT (desc->bd_iov_count == 1);
97 #else
98         LASSERT (!(md->options & (PTL_MD_IOVEC | PTL_MD_KIOV | PTL_MD_PHYS)));
99 #endif
100         if (desc->bd_iov_count == 1) {
101                 md->start = desc->bd_iov[0].iov_base;
102                 md->length = desc->bd_iov[0].iov_len;
103                 return;
104         }
105         
106         md->options |= PTL_MD_IOVEC;
107         md->start = &desc->bd_iov[0];
108         md->length = desc->bd_iov_count;
109 }
110
111 static int can_merge_iovs(ptl_md_iovec_t *existing, ptl_md_iovec_t *candidate)
112 {
113         if (existing->iov_base + existing->iov_len == candidate->iov_base) 
114                 return 1;
115 #if 0
116         /* Enable this section to provide earlier evidence of fragmented bulk */
117         CERROR("Can't merge iovs %p for %x, %p for %x\n",
118                existing->iov_base, existing->iov_len,
119                candidate->iov_base, candidate->iov_len);
120 #endif        
121         return 0;
122 }
123
124 void ptlrpc_add_bulk_page(struct ptlrpc_bulk_desc *desc, struct page *page, 
125                           int pageoffset, int len)
126 {
127         ptl_md_iovec_t *iov = &desc->bd_iov[desc->bd_iov_count];
128
129         iov->iov_base = page->addr + pageoffset;
130         iov->iov_len = len;
131
132         if (desc->bd_iov_count > 0 && can_merge_iovs(iov - 1, iov)) {
133                 (iov - 1)->iov_len += len;
134         } else {
135                 desc->bd_iov_count++;
136         }
137 }
138
139 #endif /* !__KERNEL__ */