Whamcloud - gitweb
Most of the code for the OST target.
authorbraam <braam>
Sun, 30 Dec 2001 06:17:15 +0000 (06:17 +0000)
committerbraam <braam>
Sun, 30 Dec 2001 06:17:15 +0000 (06:17 +0000)
 lib/obd_pack.c - routines for packing/unpacking of OST requests
 lib/mds_pack.c - fixes (should be 64bit safe now)
 autogen.sh - no more Makefile.in in CVS
 tests/testreq.c tests/umreq.sh tests of the RPC infrastructure

13 files changed:
lustre/include/linux/lustre_idl.h
lustre/include/linux/lustre_lib.h
lustre/include/linux/lustre_mds.h
lustre/include/linux/obd_class.h
lustre/lib/mds_pack.c
lustre/lib/obd_pack.c
lustre/ost/Makefile.am
lustre/ost/handler.c [deleted file]
lustre/ost/ost_handler.c [new file with mode: 0644]
lustre/tests/Makefile.am [new file with mode: 0644]
lustre/tests/testreq.c [new file with mode: 0644]
lustre/tests/umreq.sh [new file with mode: 0644]
lustre/utils/Makefile.am

index 201939b..c0dc843 100644 (file)
@@ -1,7 +1,24 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright (C) 2001 Cluster File Systems, Inc.
+ *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * (Un)packing of OST requests
  */
 
 #ifndef __LUSTRE_IDL_H__
  */ 
 
 /* 
- *   OBDO & OBD request records
+ *   OST requests: OBDO & OBD request records
  */
 
+
+/* opcodes */
+#define OST_GETATTR  1
+#define OST_SETATTR  2
+#define OST_BRW      3
+#define OST_CREATE   4
+#define OST_DESTROY  5
+#define OST_GETINFO  6
+
+/* packet types */
+#define OST_TYPE_REQ 1
+#define OST_TYPE_REP 2
+#define OST_TYPE_ERR 3
+
+struct ost_req_hdr { 
+       __u32 opc;
+       __u64 seqno;
+       __u32 status;
+       __u32 type;
+};
+
+struct ost_rep_hdr { 
+       __u32 opc;
+       __u64 seqno;
+       __u32 status;
+       __u32 type;
+};
+
 typedef uint64_t        obd_id;
 typedef uint64_t        obd_gr;
 typedef uint64_t        obd_time;
@@ -91,6 +136,35 @@ struct obdo {
 #define OBD_MD_FLOBDMD  (0x00010000UL)
 #define OBD_MD_FLNOTOBD (~(OBD_MD_FLOBDMD | OBD_MD_FLOBDFLG | OBD_MD_FLBLOCKS))
 
+/* request structure for OST's */
+
+#define OST_REQ_HAS_OA1  0x1
+
+struct ost_req_packed { 
+       __u32   connid;
+       __u32   cmd; 
+       struct obdo oa;
+       __u32   buflen1;
+       __u32   buflen2;
+       __u32   bufoffset1;
+       __u32   bufoffset2;
+};
+
+struct ost_rep_packed {
+       __u32   result;
+       struct obdo oa;
+       __u32   buflen1;
+       __u32   buflen2;
+       __u32   bufoffset1;
+       __u32   bufoffset2;
+};
+
+
+/* reply structure for OST's */
+
+
+
+
 
 /* 
  *   MDS REQ RECORDS
@@ -114,12 +188,18 @@ struct lustre_fid {
        __u32 f_type;
 };
 
-struct mds_req {
+
+struct mds_rep_hdr { 
+       __u32 opc;
+       __u64 seqno;
+       __u32 status;
+       __u32 type;
+};
+
+struct mds_req_packed {
        struct lustre_fid        fid1;
        struct lustre_fid        fid2;
-        char                      *name;
         int                        namelen;
-        char                      *tgt;
         int                        tgtlen;
         __u32                       valid;
         __u32                      mode;
@@ -134,21 +214,14 @@ struct mds_req {
         __u32                       minor;
         __u32                       ino;
         __u32                       generation;
+        __u32                              name_offset;
+        __u32                       tgt_offset;
 };
 
-struct mds_rep_hdr { 
-       __u32 opc;
-       __u64 seqno;
-       __u32 status;
-       __u32 type;
-};
-
-struct mds_rep {
+struct mds_rep_packed {
        struct lustre_fid        fid1;
        struct lustre_fid        fid2;
-        char                      *name;
         int                        namelen;
-        char                      *tgt;
         int                        tgtlen;
         __u32                       valid;
         __u32                      mode;
@@ -163,6 +236,8 @@ struct mds_rep {
         __u32                       minor;
         __u32                       ino;
         __u32                       generation;
+        __u32                      name_offset;
+        __u32                       tgt_offset;
 };
 
 /* 
@@ -375,5 +450,4 @@ static inline int obd_ioctl_getdata(char *buf, char *end, void *arg)
 
 
 
-
 #endif
index cda3eca..b5375d4 100644 (file)
@@ -1,3 +1,27 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Basic Lustre library routines. 
+ *
+ */
+
 #ifndef _LUSTRE_LIB_H
 #define _LUSTRE_LIB_H
 
index e293dfb..0e706d0 100644 (file)
@@ -1,3 +1,28 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * MDS data structures.  
+ * See also lustre_idl.h for wire formats of requests.
+ *
+ */
+
 #ifndef _LUSTRE_MDS_H
 #define _LUSTRE_MDS_H
 
@@ -63,6 +88,53 @@ struct mds_request {
 };
 
 
+/* more or less identical to the packed structure, except for the pointers */
+struct mds_req {
+       struct lustre_fid        fid1;
+       struct lustre_fid        fid2;
+        int                        namelen;
+        int                        tgtlen;
+        __u32                       valid;
+        __u32                      mode;
+        __u32                       uid;
+        __u32                       gid;
+        __u64                       size;
+        __u32                       mtime;
+        __u32                       ctime;
+        __u32                       atime;
+        __u32                       flags;
+        __u32                       major;
+        __u32                       minor;
+        __u32                       ino;
+        __u32                       generation;
+        char                      *name;
+        char                      *tgt;
+};
+
+/* more or less identical to the packed structure, except for the pointers */
+struct mds_rep {
+       struct lustre_fid        fid1;
+       struct lustre_fid        fid2;
+        int                        namelen;
+        int                        tgtlen;
+        __u32                       valid;
+        __u32                      mode;
+        __u32                       uid;
+        __u32                       gid;
+        __u64                       size;
+        __u32                       mtime;
+        __u32                       ctime;
+        __u32                       atime;
+        __u32                       flags;
+        __u32                       major;
+        __u32                       minor;
+        __u32                       ino;
+        __u32                       generation;
+        char                      *name;
+        char                      *tgt;
+};
+
+
 /* mds/mds_pack.c */
 int mds_pack_req(char *name, int namelen, char *tgt, int tgtlen, struct mds_req_hdr **hdr, struct mds_req **req, int *len, char **buf);
 int mds_unpack_req(char *buf, int len, struct mds_req_hdr **hdr, struct mds_req **req);
index 8a34b09..205adfd 100644 (file)
 #include <linux/lustre_lib.h>
 #include <linux/lustre_idl.h>
 #include <linux/obd.h>
-
-#include <linux/obd_ext2.h>
-#include <linux/obd_filter.h>
-#include <linux/lustre_mds.h>
-#include <linux/obd_snap.h>
-#include <linux/obd_trace.h>
-/* #include <linux/obd_fc.h> */
-#include <linux/obd_raid1.h>
-#include <linux/obd_rpc.h>
 #endif
 
 
@@ -59,6 +50,9 @@ struct obd_conn {
         uint32_t oc_id;
 };
 
+
+
+
 typedef struct {
        uint32_t len;
        char *   name;
@@ -66,6 +60,14 @@ typedef struct {
         __u8           _uuid[16]; /* uuid obd device names */
 } obd_devicename;
 
+#include <linux/obd_ext2.h>
+#include <linux/obd_filter.h>
+#include <linux/lustre_mds.h>
+#include <linux/obd_snap.h>
+#include <linux/obd_trace.h>
+/* #include <linux/obd_fc.h> */
+#include <linux/obd_raid1.h>
+#include <linux/obd_ost.h>
 
 #ifdef __KERNEL__
 /* corresponds to one of the obdx */
@@ -88,7 +90,7 @@ struct obd_device {
                 struct raid1_obd raid1;
                 struct snap_obd snap;
                struct trace_obd trace;
-                /* struct fc_obd fc; */
+                struct ost_obd ost;
         } u;
 };
 
index 88d8188..7aa43f8 100644 (file)
@@ -3,22 +3,22 @@
  *
  *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
  *
- *   This file is part of InterMezzo, http://www.inter-mezzo.org.
+ *   This file is part of Lustre, http://www.lustre.org.
  *
- *   InterMezzo is free software; you can redistribute it and/or
+ *   Lustre is free software; you can redistribute it and/or
  *   modify it under the terms of version 2 of the GNU General Public
  *   License as published by the Free Software Foundation.
  *
- *   InterMezzo is distributed in the hope that it will be useful,
+ *   Lustre is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *   GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with InterMezzo; if not, write to the Free Software
+ *   along with Lustre; if not, write to the Free Software
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * Unpacking of KML records
+ * (Un)packing of MDS and OST request records
  *
  */
 
@@ -48,6 +48,7 @@
 #include <linux/obd_support.h>
 #include <linux/lustre_lib.h>
 #include <linux/lustre_idl.h>
+#include <linux/lustre_mds.h>
 
 
 int mds_pack_req(char *name, int namelen, char *tgt, int tgtlen, 
@@ -55,9 +56,10 @@ int mds_pack_req(char *name, int namelen, char *tgt, int tgtlen,
                 int *len, char **buf)
 {
        char *ptr;
+        struct mds_req_packed *preq;
 
        *len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) + 
-               sizeof(**req); 
+               sizeof(*preq); 
 
        *buf = kmalloc(*len, GFP_KERNEL);
        if (!*buf) {
@@ -67,18 +69,21 @@ int mds_pack_req(char *name, int namelen, char *tgt, int tgtlen,
 
        memset(*buf, 0, *len); 
        *hdr = (struct mds_req_hdr *)(*buf);
-       *req = (struct mds_req *)(*buf + sizeof(**hdr));
-       ptr = *buf + sizeof(**hdr) + sizeof(**req);
+
+       preq = (struct mds_req_packed *)(*buf + sizeof(**hdr));
+       ptr = *buf + sizeof(**hdr) + sizeof(*preq);
 
        (*hdr)->type =  MDS_TYPE_REQ;
 
        (*req)->namelen = NTOH__u32(namelen);
        if (name) { 
+                preq->name_offset = (__u32)(ptr - (char *)preq);
                LOGL(name, namelen, ptr); 
        } 
 
        (*req)->tgtlen = NTOH__u32(tgtlen);
        if (tgt) { 
+                preq->tgt_offset = (__u32)(ptr - (char *)preq);
                LOGL(tgt, tgtlen, ptr);
        }
        return 0;
@@ -88,13 +93,21 @@ int mds_pack_req(char *name, int namelen, char *tgt, int tgtlen,
 int mds_unpack_req(char *buf, int len, 
                   struct mds_req_hdr **hdr, struct mds_req **req)
 {
+        struct mds_req_packed *preq;
+        __u32 off1, off2;
+        char *name, *tgt;
+
        if (len < sizeof(**hdr) + sizeof(**req)) { 
                EXIT;
                return -EINVAL;
        }
 
        *hdr = (struct mds_req_hdr *) (buf);
-       *req = (struct mds_req *) (buf + sizeof(**hdr));
+       preq = (struct mds_req_packed *) (buf + sizeof(**hdr));
+        off1 = preq->name_offset;
+        off2 = preq->tgt_offset;
+
+        *req = (struct mds_req *) (buf + sizeof(**hdr));
        (*req)->namelen = NTOH__u32((*req)->namelen); 
        (*req)->tgtlen = NTOH__u32((*req)->namelen); 
 
@@ -105,22 +118,106 @@ int mds_unpack_req(char *buf, int len,
        }
 
        if ((*req)->namelen) { 
-               (*req)->name = buf + sizeof(**hdr) + sizeof(**req);
+               name = buf + sizeof(**hdr) + off1;
        } else { 
-               (*req)->name = NULL;
+               name = NULL;
        }
 
        if ((*req)->tgtlen) { 
-               (*req)->tgt = buf + sizeof(**hdr) + sizeof(**req) + 
-                       size_round((*req)->namelen);
+               tgt = buf + sizeof(**hdr) + off2;
        } else { 
-               (*req)->tgt = NULL;
+               tgt = NULL;
+       }
+        (*req)->name = name;
+        (*req)->tgt = tgt;
+
+       EXIT;
+       return 0;
+}
+
+int mds_pack_rep(char *name, int namelen, char *tgt, int tgtlen, 
+                struct mds_rep_hdr **hdr, struct mds_rep **rep, 
+                int *len, char **buf)
+{
+       char *ptr;
+        struct mds_rep_packed *prep;
+
+       *len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) + 
+               sizeof(*prep); 
+
+       *buf = kmalloc(*len, GFP_KERNEL);
+       if (!*buf) {
+               EXIT;
+               return -ENOMEM;
+       }
+
+       memset(*buf, 0, *len); 
+       *hdr = (struct mds_rep_hdr *)(*buf);
+
+       prep = (struct mds_rep_packed *)(*buf + sizeof(**hdr));
+       ptr = *buf + sizeof(**hdr) + sizeof(*prep);
+
+       (*hdr)->type =  MDS_TYPE_REP;
+
+       (*rep)->namelen = NTOH__u32(namelen);
+       if (name) { 
+                prep->name_offset = (__u32)(ptr - (char *)prep);
+               LOGL(name, namelen, ptr); 
+       } 
+
+       (*rep)->tgtlen = NTOH__u32(tgtlen);
+       if (tgt) { 
+                prep->tgt_offset = (__u32)(ptr - (char *)prep);
+               LOGL(tgt, tgtlen, ptr);
+       }
+       return 0;
+}
+
+
+int mds_unpack_rep(char *buf, int len, 
+                  struct mds_rep_hdr **hdr, struct mds_rep **rep)
+{
+        struct mds_rep_packed *prep;
+        __u32 off1, off2;
+
+       if (len < sizeof(**hdr) + sizeof(**rep)) { 
+               EXIT;
+               return -EINVAL;
+       }
+
+       *hdr = (struct mds_rep_hdr *) (buf);
+       prep = (struct mds_rep_packed *) (buf + sizeof(**hdr));
+        off1 = prep->name_offset;
+        off2 = prep->tgt_offset;
+
+        *rep = (struct mds_rep *) (buf + sizeof(**hdr));
+       (*rep)->namelen = NTOH__u32((*rep)->namelen); 
+       (*rep)->tgtlen = NTOH__u32((*rep)->namelen); 
+
+       if (len < sizeof(**hdr) + sizeof(**rep) + (*rep)->namelen + 
+           (*rep)->tgtlen ) { 
+               EXIT;
+               return -EINVAL;
+       }
+
+       if ((*rep)->namelen) { 
+               (*rep)->name = buf + sizeof(**hdr) + off1;
+       } else { 
+               (*rep)->name = NULL;
+       }
+
+       if ((*rep)->tgtlen) { 
+               (*rep)->tgt = buf + sizeof(**hdr) + off2;
+       } else { 
+               (*rep)->tgt = NULL;
        }
+        
 
        EXIT;
        return 0;
 }
 
+#if 0
 int mds_pack_rep(char *name, int namelen, char *tgt, int tgtlen, 
                 struct mds_rep_hdr **hdr, struct mds_rep **rep, 
                 int *len, char **buf)
@@ -189,3 +286,4 @@ int mds_unpack_rep(char *buf, int len,
        EXIT;
        return 0;
 }
+#endif
index 88d8188..482826a 100644 (file)
@@ -3,22 +3,22 @@
  *
  *  Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
  *
- *   This file is part of InterMezzo, http://www.inter-mezzo.org.
+ *   This file is part of Lustre, http://www.lustre.org.
  *
- *   InterMezzo is free software; you can redistribute it and/or
+ *   Lustre is free software; you can redistribute it and/or
  *   modify it under the terms of version 2 of the GNU General Public
  *   License as published by the Free Software Foundation.
  *
- *   InterMezzo is distributed in the hope that it will be useful,
+ *   Lustre is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *   GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with InterMezzo; if not, write to the Free Software
+ *   along with Lustre; if not, write to the Free Software
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * Unpacking of KML records
+ * (Un)packing of OST requests
  *
  */
 
 #include <asm/uaccess.h>
 
 #include <linux/obd_support.h>
+#include <linux/obd_class.h>
+#include <linux/obd_ost.h>
 #include <linux/lustre_lib.h>
 #include <linux/lustre_idl.h>
 
 
-int mds_pack_req(char *name, int namelen, char *tgt, int tgtlen
-                struct mds_req_hdr **hdr, struct mds_req **req, 
+int ost_pack_req(char *buf1, int buflen1, char *buf2, int buflen2
+                struct ost_req_hdr **hdr, struct ost_req **req, 
                 int *len, char **buf)
 {
        char *ptr;
+        struct ost_req_packed *preq;
 
-       *len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) + 
-               sizeof(**req); 
+       *len = sizeof(**hdr) + size_round(buflen1) + size_round(buflen2) + 
+               sizeof(*preq); 
 
        *buf = kmalloc(*len, GFP_KERNEL);
        if (!*buf) {
@@ -66,68 +69,77 @@ int mds_pack_req(char *name, int namelen, char *tgt, int tgtlen,
        }
 
        memset(*buf, 0, *len); 
-       *hdr = (struct mds_req_hdr *)(*buf);
-       *req = (struct mds_req *)(*buf + sizeof(**hdr));
-       ptr = *buf + sizeof(**hdr) + sizeof(**req);
+       *hdr = (struct ost_req_hdr *)(*buf);
 
-       (*hdr)->type =  MDS_TYPE_REQ;
+       preq = (struct ost_req_packed *)(*buf + sizeof(**hdr));
+       ptr = *buf + sizeof(**hdr) + sizeof(*preq);
 
-       (*req)->namelen = NTOH__u32(namelen);
-       if (name) { 
-               LOGL(name, namelen, ptr); 
+       *req = (struct ost_req *)(*buf + sizeof(**hdr));
+
+       (*hdr)->type =  OST_TYPE_REQ;
+
+       (*req)->buflen1 = NTOH__u32(buflen1);
+       if (buf1) { 
+                preq->bufoffset1 = (__u32)(ptr - (char *)preq);
+               LOGL(buf1, buflen1, ptr); 
        } 
 
-       (*req)->tgtlen = NTOH__u32(tgtlen);
-       if (tgt) { 
-               LOGL(tgt, tgtlen, ptr);
+       (*req)->buflen2 = NTOH__u32(buflen2);
+       if (buf2) { 
+                preq->bufoffset2 = (__u32)(ptr - (char *)preq);
+               LOGL(buf2, buflen2, ptr);
        }
        return 0;
 }
 
-
-int mds_unpack_req(char *buf, int len, 
-                  struct mds_req_hdr **hdr, struct mds_req **req)
+int ost_unpack_req(char *buf, int len, 
+                  struct ost_req_hdr **hdr, struct ost_req **req)
 {
-       if (len < sizeof(**hdr) + sizeof(**req)) { 
+        struct ost_req_packed *reqp;
+        __u32 off1, off2;
+
+       if (len < sizeof(**hdr) + sizeof(*reqp)) { 
                EXIT;
                return -EINVAL;
        }
 
-       *hdr = (struct mds_req_hdr *) (buf);
-       *req = (struct mds_req *) (buf + sizeof(**hdr));
-       (*req)->namelen = NTOH__u32((*req)->namelen); 
-       (*req)->tgtlen = NTOH__u32((*req)->namelen); 
+       *hdr = (struct ost_req_hdr *) (buf);
+       reqp = (struct ost_req_packed *) (buf + sizeof(**hdr));
+       *req = (struct ost_req *) (buf + sizeof(**hdr));
 
-       if (len < sizeof(**hdr) + sizeof(**req) + (*req)->namelen + 
-           (*req)->tgtlen ) { 
+       (*req)->buflen1 = NTOH__u32(reqp->buflen1); 
+       (*req)->buflen2 = NTOH__u32(reqp->buflen2); 
+        off1 = NTOH__u32(reqp->bufoffset1); 
+        off2 = NTOH__u32(reqp->bufoffset2); 
+
+       if (len < sizeof(**hdr) + sizeof(*reqp) + size_round(reqp->buflen1) + 
+           size_round(reqp->buflen2) ) { 
                EXIT;
                return -EINVAL;
        }
 
-       if ((*req)->namelen) { 
-               (*req)->name = buf + sizeof(**hdr) + sizeof(**req);
+       if ((*req)->buflen1) { 
+                (*req)->buf1 = (buf + sizeof(**hdr) + off1);
        } else { 
-               (*req)->name = NULL;
+               (*req)->buf1 = 0;
        }
-
-       if ((*req)->tgtlen) { 
-               (*req)->tgt = buf + sizeof(**hdr) + sizeof(**req) + 
-                       size_round((*req)->namelen);
+       if ((*req)->buflen2) { 
+               (*req)->buf2 = (buf + sizeof(**hdr) + off2);
        } else { 
-               (*req)->tgt = NULL;
+               (*req)->buf2 = 0;
        }
 
        EXIT;
        return 0;
 }
 
-int mds_pack_rep(char *name, int namelen, char *tgt, int tgtlen, 
-                struct mds_rep_hdr **hdr, struct mds_rep **rep, 
+int ost_pack_rep(void *buf1, __u32 buflen1, void *buf2, __u32 buflen2,
+                struct ost_rep_hdr **hdr, struct ost_rep **rep, 
                 int *len, char **buf)
 {
        char *ptr;
 
-       *len = sizeof(**hdr) + size_round(namelen) + size_round(tgtlen) + 
+       *len = sizeof(**hdr) + size_round(buflen1) + size_round(buflen2) + 
                sizeof(**rep); 
 
        *buf = kmalloc(*len, GFP_KERNEL);
@@ -137,53 +149,57 @@ int mds_pack_rep(char *name, int namelen, char *tgt, int tgtlen,
        }
 
        memset(*buf, 0, *len); 
-       *hdr = (struct mds_rep_hdr *)(*buf);
-       *rep = (struct mds_rep *)(*buf + sizeof(**hdr));
+       *hdr = (struct ost_rep_hdr *)(*buf);
+       *rep = (struct ost_rep *)(*buf + sizeof(**hdr));
        ptr = *buf + sizeof(**hdr) + sizeof(**rep);
 
-       (*rep)->namelen = NTOH__u32(namelen);
-       if (name) { 
-               LOGL(name, namelen, ptr); 
+       (*rep)->buflen1 = NTOH__u32(buflen1);
+       if (buf1) { 
+               LOGL(buf1, buflen1, ptr); 
        } 
 
-       (*rep)->tgtlen = NTOH__u32(tgtlen);
-       if (tgt) { 
-               LOGL(tgt, tgtlen, ptr);
+       (*rep)->buflen2 = NTOH__u32(buflen2);
+       if (buf2) { 
+               LOGL(buf2, buflen2, ptr);
        }
        return 0;
 }
 
 
-int mds_unpack_rep(char *buf, int len, 
-                  struct mds_rep_hdr **hdr, struct mds_rep **rep)
+int ost_unpack_rep(char *buf, int len, 
+                  struct ost_rep_hdr **hdr, struct ost_rep **rep)
 {
+        struct ost_rep_packed *prep;
+        __u32 off1, off2;
+
        if (len < sizeof(**hdr) + sizeof(**rep)) { 
                EXIT;
                return -EINVAL;
        }
 
-       *hdr = (struct mds_rep_hdr *) (buf);
-       *rep = (struct mds_rep *) (buf + sizeof(**hdr));
-       (*rep)->namelen = NTOH__u32((*rep)->namelen); 
-       (*rep)->tgtlen = NTOH__u32((*rep)->namelen); 
+       *hdr = (struct ost_rep_hdr *) (buf);
+       *rep = (struct ost_rep *) (buf + sizeof(**hdr));
+       prep = (struct ost_rep_packed *) (buf + sizeof(**hdr));
+       (*rep)->buflen1 = NTOH__u32(prep->buflen1); 
+       (*rep)->buflen2 = NTOH__u32(prep->buflen2); 
+        off1 = prep->bufoffset1;
+        off2 = prep->bufoffset2;
 
-       if (len < sizeof(**hdr) + sizeof(**rep) + (*rep)->namelen + 
-           (*rep)->tgtlen ) { 
+       if (len < sizeof(**hdr) + sizeof(*prep) + size_round((*rep)->buflen1) + 
+           size_round((*rep)->buflen2) ) { 
                EXIT;
                return -EINVAL;
        }
 
-       if ((*rep)->namelen) { 
-               (*rep)->name = buf + sizeof(**hdr) + sizeof(**rep);
+       if ((*rep)->buflen1) { 
+                (*rep)->buf1 = (buf + sizeof(**hdr) + off1);
        } else { 
-               (*rep)->name = NULL;
+               (*rep)->buf1 = 0;
        }
-
-       if ((*rep)->tgtlen) { 
-               (*rep)->tgt = buf + sizeof(**hdr) + sizeof(**rep) + 
-                       size_round((*rep)->namelen);
+       if ((*rep)->buflen2) { 
+               (*rep)->buf2 = (buf + sizeof(**hdr) + off2);
        } else { 
-               (*rep)->tgt = NULL;
+               (*rep)->buf2 = 0;
        }
 
        EXIT;
index 31965cb..b91c497 100644 (file)
@@ -10,7 +10,7 @@ EXTRA_PROGRAMS = ost
 obd_pack.c: 
        ln -s ../lib/obd_pack.c .
 
-ost_SOURCES = obd_pack.c handler.c 
+ost_SOURCES = obd_pack.c ost_handler.c
 
 include $(top_srcdir)/Rules
 
diff --git a/lustre/ost/handler.c b/lustre/ost/handler.c
deleted file mode 100644 (file)
index fe58fbc..0000000
+++ /dev/null
@@ -1,434 +0,0 @@
-/*
- *  linux/mds/handler.c
- *  
- *  Lustre Metadata Server (mds) request handler
- * 
- *  Copyright (C) 2001  Cluster File Systems, Inc.
- *
- *  This code is issued under the GNU General Public License.
- *  See the file COPYING in this distribution
- *
- *  by Peter Braam <braam@clusterfs.com>
- * 
- *  This server is single threaded at present (but can easily be multi threaded). 
- * 
- */
-
-
-#define EXPORT_SYMTAB
-
-#include <linux/version.h>
-#include <linux/module.h>
-#include <linux/fs.h>
-#include <linux/stat.h>
-#include <linux/locks.h>
-#include <linux/ext2_fs.h>
-#include <linux/quotaops.h>
-#include <asm/unistd.h>
-#include <linux/obd_support.h>
-#include <linux/obd.h>
-#include <linux/lustre_lib.h>
-#include <linux/lustre_idl.h>
-#include <linux/lustre_mds.h>
-#include <linux/obd_class.h>
-
-// for testing
-static struct mds_obd *MDS;
-
-// for testing
-static int mds_queue_req(struct mds_request *req)
-{
-       
-       if (!MDS) { 
-               EXIT;
-               return -1;
-       }
-
-       list_add(&req->rq_list, &MDS->mds_reqs); 
-       init_waitqueue_head(&req->rq_wait_for_mds_rep);
-       req->rq_obd = MDS;
-       wake_up(&MDS->mds_waitq);
-       printk("-- sleeping\n");
-       interruptible_sleep_on(&req->rq_wait_for_mds_rep);
-       printk("-- done\n");
-       return 0;
-}
-
-static struct dentry *mds_fid2dentry(struct mds_obd *mds, struct lustre_fid *fid)
-{
-       struct dentry *de;
-       struct inode *inode;
-
-       inode = iget(mds->mds_sb, fid->id);
-       if (!inode) { 
-               EXIT;
-       }
-
-       de = d_alloc_root(inode);
-       if (!de) { 
-               iput(inode);
-               EXIT;
-               return NULL;
-       }
-
-       de->d_inode = inode;
-       return de;
-}
-
-int mds_getattr(struct mds_request *req)
-{
-       struct dentry *de = mds_fid2dentry(req->rq_obd, &req->rq_req->fid1);
-       struct inode *inode;
-       struct mds_rep *rep;
-       int rc;
-       
-       rc = mds_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep, 
-                         &req->rq_replen, &req->rq_repbuf);
-       if (rc) { 
-               EXIT;
-               printk("mds: out of memory\n");
-               req->rq_status = -ENOMEM;
-               return -ENOMEM;
-       }
-
-       req->rq_rephdr->seqno = req->rq_reqhdr->seqno;
-       rep = req->rq_rep;
-
-       if (!de) { 
-               EXIT;
-               req->rq_rephdr->status = -ENOENT;
-               return 0;
-       }
-
-       inode = de->d_inode;
-       rep->atime = inode->i_atime;
-       rep->ctime = inode->i_ctime;
-       rep->mtime = inode->i_mtime;
-       rep->uid = inode->i_uid;
-       rep->gid = inode->i_gid;
-       rep->size = inode->i_size;
-       rep->mode = inode->i_mode;
-
-       dput(de); 
-       return 0;
-}
-
-int mds_reply(struct mds_request *req)
-{
-       ENTRY;
-       kfree(req->rq_reqbuf);
-       req->rq_reqbuf = NULL; 
-       wake_up_interruptible(&req->rq_wait_for_mds_rep); 
-       EXIT;
-       return 0;
-}
-
-int mds_error(struct mds_request *req)
-{
-       struct mds_rep_hdr *hdr;
-
-       ENTRY;
-       hdr = kmalloc(sizeof(*hdr), GFP_KERNEL);
-       if (!hdr) { 
-               EXIT;
-               return -ENOMEM;
-       }
-
-       memset(hdr, 0, sizeof(*hdr));
-       
-       hdr->seqno = req->rq_reqhdr->seqno;
-       hdr->status = req->rq_status; 
-       hdr->type = MDS_TYPE_ERR;
-       req->rq_repbuf = (char *)hdr;
-
-       EXIT;
-       return mds_reply(req);
-}
-
-//int mds_handle(struct mds_conn *conn, int len, char *buf)
-int mds_handle(struct mds_request *req)
-{
-       int rc;
-       struct mds_req_hdr *hdr;
-
-       ENTRY;
-
-       hdr = (struct mds_req_hdr *)req->rq_reqbuf;
-
-       if (NTOH__u32(hdr->type) != MDS_TYPE_REQ) {
-               printk("lustre_mds: wrong packet type sent %d\n",
-                      NTOH__u32(hdr->type));
-               rc = -EINVAL;
-               goto out;
-       }
-
-       rc = mds_unpack_req(req->rq_reqbuf, req->rq_reqlen, 
-                           &req->rq_reqhdr, &req->rq_req);
-       if (rc) { 
-               printk("lustre_mds: Invalid request\n");
-               EXIT; 
-               goto out;
-       }
-
-       switch (req->rq_reqhdr->opc) { 
-
-       case MDS_GETATTR:
-               CDEBUG(D_INODE, "getattr\n");
-               rc = mds_getattr(req);
-               break;
-
-       case MDS_OPEN:
-               return mds_getattr(req);
-
-       case MDS_SETATTR:
-               return mds_getattr(req);
-
-       case MDS_CREATE:
-               return mds_getattr(req);
-
-       case MDS_MKDIR:
-               return mds_getattr(req);
-
-       case MDS_RMDIR:
-               return mds_getattr(req);
-
-       case MDS_SYMLINK:
-               return mds_getattr(req);
-       case MDS_LINK:
-               return mds_getattr(req);
-  
-       case MDS_MKNOD:
-               return mds_getattr(req);
-
-       case MDS_UNLINK:
-               return mds_getattr(req);
-
-       case MDS_RENAME:
-               return mds_getattr(req);
-
-       default:
-               return mds_error(req);
-       }
-
-out:
-       if (rc) { 
-               printk("mds: processing error %d\n", rc);
-               mds_error(req);
-       } else { 
-               CDEBUG(D_INODE, "sending reply\n"); 
-               mds_reply(req); 
-       }
-
-       return 0;
-}
-
-
-static void mds_timer_run(unsigned long __data)
-{
-       struct task_struct * p = (struct task_struct *) __data;
-
-       wake_up_process(p);
-}
-
-int mds_main(void *arg)
-{
-       struct mds_obd *mds = (struct mds_obd *) arg;
-       struct timer_list timer;
-
-       lock_kernel();
-       daemonize();
-       spin_lock_irq(&current->sigmask_lock);
-       sigfillset(&current->blocked);
-       recalc_sigpending(current);
-       spin_unlock_irq(&current->sigmask_lock);
-
-       sprintf(current->comm, "lustre_mds");
-
-       /* Set up an interval timer which can be used to trigger a
-           wakeup after the interval expires */
-       init_timer(&timer);
-       timer.data = (unsigned long) current;
-       timer.function = mds_timer_run;
-       mds->mds_timer = &timer;
-
-       /* Record that the  thread is running */
-       mds->mds_thread = current;
-       wake_up(&mds->mds_done_waitq); 
-
-       printk(KERN_INFO "lustre_mds starting.  Commit interval %d seconds\n",
-                       mds->mds_interval / HZ);
-
-       /* XXX maintain a list of all managed devices: insert here */
-
-       /* And now, wait forever for commit wakeup events. */
-       while (1) {
-               struct mds_request *request;
-               int rc; 
-
-               if (mds->mds_flags & MDS_UNMOUNT)
-                       break;
-
-
-               wake_up(&mds->mds_done_waitq);
-               interruptible_sleep_on(&mds->mds_waitq);
-
-               CDEBUG(D_INODE, "lustre_mds wakes\n");
-               CDEBUG(D_INODE, "pick up req here and continue\n"); 
-
-               if (list_empty(&mds->mds_reqs)) { 
-                       CDEBUG(D_INODE, "woke because of timer\n"); 
-               } else { 
-                       request = list_entry(mds->mds_reqs.next, 
-                                            struct mds_request, rq_list);
-                       list_del(&request->rq_list);
-                       rc = mds_handle(request); 
-               }
-       }
-
-       del_timer_sync(mds->mds_timer);
-
-       /* XXX maintain a list of all managed devices: cleanup here */
-
-       mds->mds_thread = NULL;
-       wake_up(&mds->mds_done_waitq);
-       printk("lustre_mds: exiting\n");
-       return 0;
-}
-
-static void mds_stop_srv_thread(struct mds_obd *mds)
-{
-       mds->mds_flags |= MDS_UNMOUNT;
-
-       while (mds->mds_thread) {
-               wake_up(&mds->mds_waitq);
-               sleep_on(&mds->mds_done_waitq);
-       }
-}
-
-static void mds_start_srv_thread(struct mds_obd *mds)
-{
-       init_waitqueue_head(&mds->mds_waitq);
-       init_waitqueue_head(&mds->mds_done_waitq);
-       kernel_thread(mds_main, (void *)mds, 
-                     CLONE_VM | CLONE_FS | CLONE_FILES);
-       while (!mds->mds_thread) 
-               sleep_on(&mds->mds_done_waitq);
-}
-
-/* mount the file system (secretly) */
-static int mds_setup(struct obd_device *obddev, obd_count len,
-                       void *buf)
-                       
-{
-       struct obd_ioctl_data* data = buf;
-       struct mds_obd *mds = &obddev->u.mds;
-       struct vfsmount *mnt;
-       int err; 
-        ENTRY;
-       
-       mnt = do_kern_mount(data->ioc_inlbuf2, 0, 
-                           data->ioc_inlbuf1, NULL); 
-       err = PTR_ERR(mnt);
-       if (IS_ERR(mnt)) { 
-               EXIT;
-               return err;
-       }
-
-       mds->mds_sb = mnt->mnt_root->d_inode->i_sb;
-       if (!obddev->u.mds.mds_sb) {
-               EXIT;
-               return -ENODEV;
-       }
-
-       INIT_LIST_HEAD(&mds->mds_reqs);
-       mds->mds_thread = NULL;
-       mds->mds_flags = 0;
-       mds->mds_interval = 3 * HZ;
-       mds->mds_vfsmnt = mnt;
-       obddev->u.mds.mds_fstype = strdup(data->ioc_inlbuf2);
-
-       mds->mds_ctxt.pwdmnt = mnt;
-       mds->mds_ctxt.pwd = mnt->mnt_root;
-       mds->mds_ctxt.fs = KERNEL_DS;
-       MDS = mds;
-
-       spin_lock_init(&obddev->u.mds.fo_lock);
-
-       mds_start_srv_thread(mds);
-
-        MOD_INC_USE_COUNT;
-        EXIT; 
-        return 0;
-} 
-
-static int mds_cleanup(struct obd_device * obddev)
-{
-        struct super_block *sb;
-       struct mds_obd *mds = &obddev->u.mds;
-
-        ENTRY;
-
-        if ( !(obddev->obd_flags & OBD_SET_UP) ) {
-                EXIT;
-                return 0;
-        }
-
-        if ( !list_empty(&obddev->obd_gen_clients) ) {
-                printk(KERN_WARNING __FUNCTION__ ": still has clients!\n");
-                EXIT;
-                return -EBUSY;
-        }
-
-       MDS = NULL;
-       mds_stop_srv_thread(mds);
-        sb = mds->mds_sb;
-        if (!mds->mds_sb){
-                EXIT;
-                return 0;
-        }
-
-       if (!list_empty(&mds->mds_reqs)) {
-               // XXX reply with errors and clean up
-               CDEBUG(D_INODE, "Request list not empty!\n");
-       }
-
-       unlock_kernel();
-       mntput(mds->mds_vfsmnt); 
-        mds->mds_sb = 0;
-       kfree(mds->mds_fstype);
-       lock_kernel();
-       
-
-        MOD_DEC_USE_COUNT;
-        EXIT;
-        return 0;
-}
-
-/* use obd ops to offer management infrastructure */
-static struct obd_ops mds_obd_ops = {
-        o_setup:       mds_setup,
-        o_cleanup:     mds_cleanup,
-};
-
-static int __init mds_init(void)
-{
-        obd_register_type(&mds_obd_ops, LUSTRE_MDS_NAME);
-       return 0;
-}
-
-static void __exit mds_exit(void)
-{
-       obd_unregister_type(LUSTRE_MDS_NAME);
-}
-
-MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
-MODULE_DESCRIPTION("Lustre Metadata Server (MDS) v0.01");
-MODULE_LICENSE("GPL");
-
-
-// for testing (maybe this stays)
-EXPORT_SYMBOL(mds_queue_req);
-
-module_init(mds_init);
-module_exit(mds_exit);
diff --git a/lustre/ost/ost_handler.c b/lustre/ost/ost_handler.c
new file mode 100644 (file)
index 0000000..b36beca
--- /dev/null
@@ -0,0 +1,439 @@
+/*
+ *  linux/mds/handler.c
+ *  
+ *  Lustre Object Server Module (OST)
+ * 
+ *  Copyright (C) 2001  Cluster File Systems, Inc.
+ *
+ *  This code is issued under the GNU General Public License.
+ *  See the file COPYING in this distribution
+ *
+ *  by Peter Braam <braam@clusterfs.com>
+ * 
+ *  This server is single threaded at present (but can easily be multi threaded). 
+ * 
+ */
+
+
+#define EXPORT_SYMTAB
+
+#include <linux/version.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/stat.h>
+#include <linux/locks.h>
+#include <linux/ext2_fs.h>
+#include <linux/quotaops.h>
+#include <asm/unistd.h>
+#include <linux/obd_support.h>
+#include <linux/obd.h>
+#include <linux/obd_class.h>
+#include <linux/lustre_lib.h>
+#include <linux/lustre_idl.h>
+#include <linux/lustre_mds.h>
+#include <linux/obd_class.h>
+
+
+// for testing
+static struct ost_obd *OST;
+
+// for testing
+static int ost_queue_req(struct ost_request *req)
+{
+       
+       if (!OST) { 
+               EXIT;
+               return -1;
+       }
+
+       list_add(&req->rq_list, &OST->ost_reqs); 
+       init_waitqueue_head(&req->rq_wait_for_ost_rep);
+       req->rq_obd = OST;
+       wake_up(&OST->ost_waitq);
+       printk("-- sleeping\n");
+       interruptible_sleep_on(&req->rq_wait_for_ost_rep);
+       printk("-- done\n");
+       return 0;
+}
+
+int ost_reply(struct ost_request *req)
+{
+       ENTRY;
+       kfree(req->rq_reqbuf);
+       req->rq_reqbuf = NULL; 
+       wake_up_interruptible(&req->rq_wait_for_ost_rep); 
+       EXIT;
+       return 0;
+}
+
+int ost_error(struct ost_request *req)
+{
+       struct ost_rep_hdr *hdr;
+
+       ENTRY;
+       hdr = kmalloc(sizeof(*hdr), GFP_KERNEL);
+       if (!hdr) { 
+               EXIT;
+               return -ENOMEM;
+       }
+
+       memset(hdr, 0, sizeof(*hdr));
+       
+       hdr->seqno = req->rq_reqhdr->seqno;
+       hdr->status = req->rq_status; 
+       hdr->type = OST_TYPE_ERR;
+       req->rq_repbuf = (char *)hdr;
+
+       EXIT;
+       return ost_reply(req);
+}
+
+static int ost_destroy(struct ost_obd *ost, struct ost_request *req)
+{
+       struct obd_conn conn; 
+       int rc;
+
+       ENTRY;
+       
+       conn.oc_id = req->rq_req->connid;
+       conn.oc_dev = ost->ost_tgt;
+
+       rc = ost_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
+                         &req->rq_reqlen, &req->rq_reqbuf); 
+       if (rc) { 
+               printk("ost_destroy: cannot pack reply\n"); 
+               return rc;
+       }
+
+       req->rq_rep->result =ost->ost_tgt->obd_type->typ_ops->o_destroy
+               (&conn, &req->rq_req->oa); 
+
+       EXIT;
+       return 0;
+}
+
+static int ost_getattr(struct ost_obd *ost, struct ost_request *req)
+{
+       struct obd_conn conn; 
+       int rc;
+
+       ENTRY;
+       
+       conn.oc_id = req->rq_req->connid;
+       conn.oc_dev = ost->ost_tgt;
+
+       rc = ost_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
+                         &req->rq_reqlen, &req->rq_reqbuf); 
+       if (rc) { 
+               printk("ost_getattr: cannot pack reply\n"); 
+               return rc;
+       }
+       req->rq_rep->oa.o_id = req->rq_req->oa.o_id;
+
+       req->rq_rep->result =ost->ost_tgt->obd_type->typ_ops->o_getattr
+               (&conn, &req->rq_rep->oa); 
+
+       EXIT;
+       return 0;
+}
+
+static int ost_create(struct ost_obd *ost, struct ost_request *req)
+{
+       struct obd_conn conn; 
+       int rc;
+
+       ENTRY;
+       
+       conn.oc_id = req->rq_req->connid;
+       conn.oc_dev = ost->ost_tgt;
+
+       rc = ost_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
+                         &req->rq_reqlen, &req->rq_reqbuf); 
+       if (rc) { 
+               printk("ost_create: cannot pack reply\n"); 
+               return rc;
+       }
+
+       memcpy(&req->rq_rep->oa, &req->rq_req->oa, sizeof(req->rq_req->oa));
+
+       req->rq_rep->result =ost->ost_tgt->obd_type->typ_ops->o_create
+               (&conn, &req->rq_rep->oa); 
+
+       EXIT;
+       return 0;
+}
+
+
+static int ost_setattr(struct ost_obd *ost, struct ost_request *req)
+{
+       struct obd_conn conn; 
+       int rc;
+
+       ENTRY;
+       
+       conn.oc_id = req->rq_req->connid;
+       conn.oc_dev = ost->ost_tgt;
+
+       rc = ost_pack_rep(NULL, 0, NULL, 0, &req->rq_rephdr, &req->rq_rep,
+                         &req->rq_reqlen, &req->rq_reqbuf); 
+       if (rc) { 
+               printk("ost_setattr: cannot pack reply\n"); 
+               return rc;
+       }
+
+       memcpy(&req->rq_rep->oa, &req->rq_req->oa, sizeof(req->rq_req->oa));
+
+       req->rq_rep->result =ost->ost_tgt->obd_type->typ_ops->o_setattr
+               (&conn, &req->rq_rep->oa); 
+
+       EXIT;
+       return 0;
+}
+
+
+//int ost_handle(struct ost_conn *conn, int len, char *buf)
+int ost_handle(struct ost_obd *ost, struct ost_request *req)
+{
+       int rc;
+       struct ost_req_hdr *hdr;
+
+       ENTRY;
+
+       hdr = (struct ost_req_hdr *)req->rq_reqbuf;
+
+       if (NTOH__u32(hdr->type) != OST_TYPE_REQ) {
+               printk("lustre_ost: wrong packet type sent %d\n",
+                      NTOH__u32(hdr->type));
+               rc = -EINVAL;
+               goto out;
+       }
+
+       rc = ost_unpack_req(req->rq_reqbuf, req->rq_reqlen, 
+                           &req->rq_reqhdr, &req->rq_req);
+       if (rc) { 
+               printk("lustre_ost: Invalid request\n");
+               EXIT; 
+               goto out;
+       }
+
+       switch (req->rq_reqhdr->opc) { 
+
+       case OST_CREATE:
+               CDEBUG(D_INODE, "create\n");
+               rc = ost_create(ost, req);
+               break;
+       case OST_DESTROY:
+               CDEBUG(D_INODE, "destroy\n");
+               rc = ost_destroy(ost, req);
+               break;
+       case OST_GETATTR:
+               CDEBUG(D_INODE, "getattr\n");
+               rc = ost_getattr(ost, req);
+               break;
+       case OST_SETATTR:
+               CDEBUG(D_INODE, "setattr\n");
+               rc = ost_setattr(ost, req);
+               break;
+
+       default:
+               return ost_error(req);
+       }
+
+out:
+       if (rc) { 
+               printk("ost: processing error %d\n", rc);
+               ost_error(req);
+       } else { 
+               CDEBUG(D_INODE, "sending reply\n"); 
+               ost_reply(req); 
+       }
+
+       return 0;
+}
+
+int ost_main(void *arg)
+{
+       struct ost_obd *ost = (struct ost_obd *) arg;
+
+       lock_kernel();
+       daemonize();
+       spin_lock_irq(&current->sigmask_lock);
+       sigfillset(&current->blocked);
+       recalc_sigpending(current);
+       spin_unlock_irq(&current->sigmask_lock);
+
+       sprintf(current->comm, "lustre_ost");
+
+       /* Record that the  thread is running */
+       ost->ost_thread = current;
+       wake_up(&ost->ost_done_waitq); 
+
+       /* XXX maintain a list of all managed devices: insert here */
+
+       /* And now, wait forever for commit wakeup events. */
+       while (1) {
+               struct ost_request *request;
+               int rc; 
+
+               if (ost->ost_flags & OST_EXIT)
+                       break;
+
+
+               wake_up(&ost->ost_done_waitq);
+               interruptible_sleep_on(&ost->ost_waitq);
+
+               CDEBUG(D_INODE, "lustre_ost wakes\n");
+               CDEBUG(D_INODE, "pick up req here and continue\n"); 
+
+               if (list_empty(&ost->ost_reqs)) { 
+                       CDEBUG(D_INODE, "woke because of timer\n"); 
+               } else { 
+                       request = list_entry(ost->ost_reqs.next, 
+                                            struct ost_request, rq_list);
+                       list_del(&request->rq_list);
+                       rc = ost_handle(ost, request); 
+               }
+       }
+
+       /* XXX maintain a list of all managed devices: cleanup here */
+
+       ost->ost_thread = NULL;
+       wake_up(&ost->ost_done_waitq);
+       printk("lustre_ost: exiting\n");
+       return 0;
+}
+
+static void ost_stop_srv_thread(struct ost_obd *ost)
+{
+       ost->ost_flags |= OST_EXIT;
+
+       while (ost->ost_thread) {
+               wake_up(&ost->ost_waitq);
+               sleep_on(&ost->ost_done_waitq);
+       }
+}
+
+static void ost_start_srv_thread(struct ost_obd *ost)
+{
+       init_waitqueue_head(&ost->ost_waitq);
+       init_waitqueue_head(&ost->ost_done_waitq);
+       kernel_thread(ost_main, (void *)ost, 
+                     CLONE_VM | CLONE_FS | CLONE_FILES);
+       while (!ost->ost_thread) 
+               sleep_on(&ost->ost_done_waitq);
+}
+
+/* mount the file system (secretly) */
+static int ost_setup(struct obd_device *obddev, obd_count len,
+                       void *buf)
+                       
+{
+       struct obd_ioctl_data* data = buf;
+       struct ost_obd *ost = &obddev->u.ost;
+       struct obd_device *tgt;
+       int err; 
+        ENTRY;
+
+       if (data->ioc_dev  < 0 || data->ioc_dev > MAX_OBD_DEVICES) { 
+               EXIT;
+               return -ENODEV;
+       }
+
+        tgt = &obd_dev[data->ioc_dev];
+       
+        if ( ! (tgt->obd_flags & OBD_ATTACHED) || 
+             ! (tgt->obd_flags & OBD_SET_UP) ){
+                printk("device not attached or not set up (%d)\n", 
+                       data->ioc_dev);
+                EXIT;
+               return -EINVAL;
+        } 
+
+       err = tgt->obd_type->typ_ops->o_connect(&ost->ost_conn);
+       if (err) { 
+               printk("lustre ost: fail to connect to device %d\n", 
+                      data->ioc_dev); 
+               return -EINVAL;
+       }
+
+       INIT_LIST_HEAD(&ost->ost_reqs);
+       ost->ost_thread = NULL;
+       ost->ost_flags = 0;
+       OST = ost;
+
+       spin_lock_init(&obddev->u.ost.fo_lock);
+
+       ost_start_srv_thread(ost);
+
+        MOD_INC_USE_COUNT;
+        EXIT; 
+        return 0;
+} 
+
+static int ost_cleanup(struct obd_device * obddev)
+{
+       struct ost_obd *ost = &obddev->u.ost;
+       struct obd_device *tgt;
+       int err;
+
+        ENTRY;
+
+        if ( !(obddev->obd_flags & OBD_SET_UP) ) {
+                EXIT;
+                return 0;
+        }
+
+        if ( !list_empty(&obddev->obd_gen_clients) ) {
+                printk(KERN_WARNING __FUNCTION__ ": still has clients!\n");
+                EXIT;
+                return -EBUSY;
+        }
+
+       OST = NULL;
+       ost_stop_srv_thread(ost);
+
+       if (!list_empty(&ost->ost_reqs)) {
+               // XXX reply with errors and clean up
+               CDEBUG(D_INODE, "Request list not empty!\n");
+       }
+
+       tgt = ost->ost_tgt;
+       err = tgt->obd_type->typ_ops->o_disconnect(&ost->ost_conn);
+       if (err) { 
+               printk("lustre ost: fail to disconnect device\n");
+               return -EINVAL;
+       }
+       
+
+        MOD_DEC_USE_COUNT;
+        EXIT;
+        return 0;
+}
+
+/* use obd ops to offer management infrastructure */
+static struct obd_ops ost_obd_ops = {
+        o_setup:       ost_setup,
+        o_cleanup:     ost_cleanup,
+};
+
+static int __init ost_init(void)
+{
+        obd_register_type(&ost_obd_ops, LUSTRE_OST_NAME);
+       return 0;
+}
+
+static void __exit ost_exit(void)
+{
+       obd_unregister_type(LUSTRE_OST_NAME);
+}
+
+MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
+MODULE_DESCRIPTION("Lustre Object Storage Target (OST) v0.01");
+MODULE_LICENSE("GPL");
+
+
+// for testing (maybe this stays)
+EXPORT_SYMBOL(ost_queue_req);
+
+module_init(ost_init);
+module_exit(ost_exit);
diff --git a/lustre/tests/Makefile.am b/lustre/tests/Makefile.am
new file mode 100644 (file)
index 0000000..4caa4b0
--- /dev/null
@@ -0,0 +1,7 @@
+CFLAGS:=-g -I. -I/usr/include/glib-1.2 -I/usr/lib/glib/include -I../include -Wall
+KFLAGS:=
+CPPFLAGS :=
+# LDADD := -lreadline -ltermcap # -lefence
+bin_PROGRAMS = testreq
+testreq_SOURCES = testreq.c
+
diff --git a/lustre/tests/testreq.c b/lustre/tests/testreq.c
new file mode 100644 (file)
index 0000000..b47b31c
--- /dev/null
@@ -0,0 +1,26 @@
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+
+#define IOC_REQUEST_GETATTR            _IOWR('f', 30, long)
+
+int main(int argc, char **argv)
+{
+       int fd, rc; 
+       int cmd = IOC_REQUEST_GETATTR;
+
+       printf("ioctl type %d, nr %d size %d\n", 
+              _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd));
+
+       fd = open("/dev/request", O_RDONLY);
+       if (fd == -1) { 
+               printf("error opening /dev/request: %s\n", strerror(errno));
+               return 1;
+       }
+
+       rc = ioctl(fd, IOC_REQUEST_GETATTR, NULL); 
+       printf("result: %d\n", rc); 
+       return 0;
+}
diff --git a/lustre/tests/umreq.sh b/lustre/tests/umreq.sh
new file mode 100644 (file)
index 0000000..a8f0bca
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+R=/r
+
+insmod /lib/modules/2.4.17/kernel/drivers/block/loop.o
+dd if=/dev/zero of=/tmp/fs bs=1024 count=10000
+mke2fs -F /tmp/fs
+losetup /dev/loop/0 /tmp/fs
+
+
+insmod $R/usr/src/obd/class/obdclass.o 
+insmod $R/usr/src/obd/mds/mds.o
+mknod /dev/obd c 10 241
+
+$R/usr/src/obd/utils/obdctl <<EOF
+device 0
+attach mds
+setup /dev/loop/0 ext2
+quit
+EOF
+
+
+insmod $R/usr/src/obd/llight/llight.o
+mknod /dev/request c 10 244
+$R/usr/src/obd/utils/testreq
+
+
index 1dc91d6..2e8010b 100644 (file)
@@ -5,7 +5,6 @@ CFLAGS:=-g -I. -I/usr/include/glib-1.2 -I/usr/lib/glib/include -I../include -Wal
 KFLAGS:=
 CPPFLAGS :=
 LDADD := -lreadline -ltermcap # -lefence
-bin_PROGRAMS = obdctl testreq
+bin_PROGRAMS = obdctl
 obdctl_SOURCES = parser.c obdctl.c
-testreq_SOURCES = testreq.c