1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
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.
21 * (Un)packing of OST requests
25 #include <linux/module.h>
26 #include <linux/errno.h>
27 #include <linux/kernel.h>
28 #include <linux/major.h>
29 #include <linux/sched.h>
31 #include <linux/slab.h>
32 #include <linux/ioport.h>
33 #include <linux/fcntl.h>
34 #include <linux/delay.h>
35 #include <linux/skbuff.h>
36 #include <linux/proc_fs.h>
38 #include <linux/poll.h>
39 #include <linux/init.h>
40 #include <linux/list.h>
42 #include <asm/segment.h>
43 #include <asm/system.h>
45 #include <asm/uaccess.h>
47 #define DEBUG_SUBSYSTEM S_CLASS
49 #include <linux/obd_class.h>
50 #include <linux/lustre_net.h>
52 int lustre_pack_msg(int count, int *lens, char **bufs, int *len, char **buf)
59 for (i=0 ; i<count; i++) {
60 size += size_round(lens[i]);
62 *len = sizeof(*m) + size;
64 OBD_ALLOC(*buf, *len);
70 memset(*buf, 0, *len);
71 m = (struct lustre_msg *)(*buf);
72 m->type = PTL_RPC_REQUEST;
74 m->bufcount = HTON__u32(count);
75 for (i=0 ; i<count; i++) {
76 m->buflens[i] = HTON__u32(lens[i]);
79 ptr = *buf + sizeof(*m) + sizeof(__u32) * count;
80 for (i=0 ; i<count ; i++) {
81 LOGL(buf[i], lens[i], ptr);
87 int lustre_unpack_msg(char *buf, int len)
89 struct lustre_msg *m = (struct lustre_msg *)buf;
92 required_len = sizeof(*m);
93 if (len < required_len) {
97 m->bufcount = NTOH__u32(m->bufcount);
99 required_len += m->bufcount * sizeof(__u32);
100 if (len < required_len) {
104 for (i=0; i<m->bufcount; i++) {
105 m->buflens[i] = NTOH__u32(m->buflens[i]);
106 required_len += size_round(m->buflens[i]);
109 if (len < required_len) {
117 void *lustre_msg_buf(int n, struct lustre_msg *m)
122 if (n >= m->bufcount || n < 0) {
123 CERROR("referencing bad sub buffer!\n");
127 if (m->buflens[n] == 0)
130 offset = sizeof(*m) + m->bufcount * sizeof(__u32);
132 for (i=0; i < n; i++ )
133 offset += size_round(m->buflens[i]);
135 return (char *)m + offset;