Whamcloud - gitweb
smash the HEAD with the contents of b_cmd. HEAD_PRE_CMD_SMASH and
[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 #ifndef CRAY_PORTALS
39 void pers_bulk_add_page(struct ptlrpc_bulk_desc *desc, struct page *page,
40                         int pageoffset, int len)
41 {
42         ptl_kiov_t *kiov = &desc->bd_iov[desc->bd_iov_count];
43
44         kiov->kiov_page = page;
45         kiov->kiov_offset = pageoffset;
46         kiov->kiov_len = len;
47
48         desc->bd_iov_count++;
49 }
50 #else
51 void pers_bulk_add_page(struct ptlrpc_bulk_desc *desc, struct page *page,
52                         int pageoffset, int len)
53 {
54         struct iovec *iov = &desc->bd_iov[desc->bd_iov_count];
55
56         /* Should get a compiler warning if sizeof(physaddr) > sizeof(void *) */
57         iov->iov_base = (void *)(page_to_phys(page) + pageoffset);
58         iov->iov_len = len;
59
60         desc->bd_iov_count++;
61 }
62 #endif
63
64 #else /* !__KERNEL__ */
65
66 int can_merge_iovs(struct iovec *existing, struct iovec *candidate)
67 {
68         if (existing->iov_base + existing->iov_len == candidate->iov_base)
69                 return 1;
70         return 0;
71 }
72 void pers_bulk_add_page(struct ptlrpc_bulk_desc *desc, struct page *page, 
73                         int pageoffset, int len)
74 {
75         struct iovec *iov = &desc->bd_iov[desc->bd_iov_count];
76
77         iov->iov_base = page->addr + pageoffset;
78         iov->iov_len = len;
79
80         if (desc->bd_iov_count > 0 && can_merge_iovs(iov - 1, iov)) {
81                 (iov - 1)->iov_len += len;
82         } else {
83                 desc->bd_iov_count++;
84         }
85 }
86 #endif