1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2004 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
22 #define DEBUG_SUBSYSTEM S_RPC
26 #include <liblustre.h>
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>
35 #include "ptlrpc_internal.h"
39 void ptlrpc_fill_bulk_md (ptl_md_t *md, struct ptlrpc_bulk_desc *desc)
41 LASSERT (desc->bd_iov_count <= PTLRPC_MAX_BRW_PAGES);
42 LASSERT (!(md->options & (PTL_MD_IOVEC | PTL_MD_KIOV | PTL_MD_PHYS)));
44 md->options |= PTL_MD_KIOV;
45 md->start = &desc->bd_iov[0];
46 md->length = desc->bd_iov_count;
49 void ptlrpc_add_bulk_page(struct ptlrpc_bulk_desc *desc, struct page *page,
50 int pageoffset, int len)
52 ptl_kiov_t *kiov = &desc->bd_iov[desc->bd_iov_count];
54 kiov->kiov_page = page;
55 kiov->kiov_offset = pageoffset;
61 void ptlrpc_fill_bulk_md (ptl_md_t *md, struct ptlrpc_bulk_desc *desc)
63 LASSERT (desc->bd_iov_count <= PTLRPC_MAX_BRW_PAGES);
64 LASSERT (!(md->options & (PTL_MD_IOVEC | PTL_MD_KIOV | PTL_MD_PHYS)));
66 md->options |= (PTL_MD_IOVEC | PTL_MD_PHYS);
67 md->start = &desc->bd_iov[0];
68 md->length = desc->bd_iov_count;
71 void ptlrpc_add_bulk_page(struct ptlrpc_bulk_desc *desc, struct page *page,
72 int pageoffset, int len)
74 ptl_md_iovec_t *iov = &desc->bd_iov[desc->bd_iov_count];
76 /* Should get a compiler warning if sizeof(physaddr) > sizeof(void *) */
77 iov->iov_base = (void *)(page_to_phys(page) + pageoffset);
84 #else /* !__KERNEL__ */
85 void ptlrpc_fill_bulk_md(ptl_md_t *md, struct ptlrpc_bulk_desc *desc)
87 LASSERT (!(md->options & (PTL_MD_IOVEC | PTL_MD_KIOV | PTL_MD_PHYS)));
89 if (desc->bd_iov_count == 1) {
90 md->start = desc->bd_iov[0].iov_base;
91 md->length = desc->bd_iov[0].iov_len;
98 md->options |= PTL_MD_IOVEC;
99 md->start = &desc->bd_iov[0];
100 md->length = desc->bd_iov_count;
103 static int can_merge_iovs(ptl_md_iovec_t *existing, ptl_md_iovec_t *candidate)
105 if (existing->iov_base + existing->iov_len == candidate->iov_base)
107 /* XXX it's good to have an warning here, but user-level echo_client
108 * will hit this. reenable it when we fixed echo_client.
111 CERROR("Can't merge iovs %p for %x, %p for %x\n",
112 existing->iov_base, existing->iov_len,
113 candidate->iov_base, candidate->iov_len);
118 void ptlrpc_add_bulk_page(struct ptlrpc_bulk_desc *desc, struct page *page,
119 int pageoffset, int len)
121 ptl_md_iovec_t *iov = &desc->bd_iov[desc->bd_iov_count];
123 iov->iov_base = page->addr + pageoffset;
126 if (desc->bd_iov_count > 0 && can_merge_iovs(iov - 1, iov)) {
127 (iov - 1)->iov_len += len;
129 desc->bd_iov_count++;