1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_RPC
41 #include <liblustre.h>
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>
50 #include "ptlrpc_internal.h"
54 void ptlrpc_fill_bulk_md (lnet_md_t *md, struct ptlrpc_bulk_desc *desc)
56 LASSERT (desc->bd_iov_count <= PTLRPC_MAX_BRW_PAGES);
57 LASSERT (!(md->options & (LNET_MD_IOVEC | LNET_MD_KIOV | LNET_MD_PHYS)));
59 md->options |= LNET_MD_KIOV;
60 md->length = desc->bd_iov_count;
62 md->start = desc->bd_enc_iov;
64 md->start = desc->bd_iov;
67 void ptlrpc_add_bulk_page(struct ptlrpc_bulk_desc *desc, cfs_page_t *page,
68 int pageoffset, int len)
70 lnet_kiov_t *kiov = &desc->bd_iov[desc->bd_iov_count];
72 kiov->kiov_page = page;
73 kiov->kiov_offset = pageoffset;
79 #else /* !__KERNEL__ */
81 void ptlrpc_fill_bulk_md(lnet_md_t *md, struct ptlrpc_bulk_desc *desc)
83 LASSERT (!(md->options & (LNET_MD_IOVEC | LNET_MD_KIOV | LNET_MD_PHYS)));
84 if (desc->bd_iov_count == 1) {
85 md->start = desc->bd_iov[0].iov_base;
86 md->length = desc->bd_iov[0].iov_len;
90 md->options |= LNET_MD_IOVEC;
91 md->start = &desc->bd_iov[0];
92 md->length = desc->bd_iov_count;
95 static int can_merge_iovs(lnet_md_iovec_t *existing, lnet_md_iovec_t *candidate)
97 if (existing->iov_base + existing->iov_len == candidate->iov_base)
100 /* Enable this section to provide earlier evidence of fragmented bulk */
101 CERROR("Can't merge iovs %p for %x, %p for %x\n",
102 existing->iov_base, existing->iov_len,
103 candidate->iov_base, candidate->iov_len);
108 void ptlrpc_add_bulk_page(struct ptlrpc_bulk_desc *desc, cfs_page_t *page,
109 int pageoffset, int len)
111 lnet_md_iovec_t *iov = &desc->bd_iov[desc->bd_iov_count];
113 iov->iov_base = page->addr + pageoffset;
116 if (desc->bd_iov_count > 0 && can_merge_iovs(iov - 1, iov)) {
117 (iov - 1)->iov_len += len;
119 desc->bd_iov_count++;
123 #endif /* !__KERNEL__ */