Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[fs/lustre-release.git] / lustre / include / linux / lustre_lib.h
index 6f38be0..c43cf95 100644 (file)
 
 #ifndef __KERNEL__
 # include <string.h>
+# include <sys/types.h>
 #else
 # include <asm/semaphore.h>
 # include <linux/sched.h>
 # include <linux/signal.h>
+# include <linux/types.h>
 #endif
-#include <linux/types.h>
 #include <linux/portals_lib.h>
 #include <linux/kp30.h> /* XXX just for LASSERT! */
 #include <linux/lustre_idl.h>
 
 /* target.c */
 struct ptlrpc_request;
-struct obd_device;
 struct recovd_data;
 struct recovd_obd;
 struct obd_export;
 #include <linux/lustre_ha.h>
 #include <linux/lustre_net.h>
-
+#include <linux/lustre_compat25.h>
 
 int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler);
 int target_handle_disconnect(struct ptlrpc_request *req);
 int target_handle_reconnect(struct lustre_handle *conn, struct obd_export *exp,
                             struct obd_uuid *cluuid);
-int target_revoke_connection(struct recovd_data *rd, int phase);
+int target_handle_ping(struct ptlrpc_request *req);
+void target_cancel_recovery_timer(struct obd_device *obd);
 
 #define OBD_RECOVERY_TIMEOUT (obd_timeout * 5 * HZ / 2) /* *waves hands* */
 void target_start_recovery_timer(struct obd_device *obd, svc_handler_t handler);
@@ -71,18 +72,26 @@ void target_abort_recovery(void *data);
 int target_queue_recovery_request(struct ptlrpc_request *req,
                                   struct obd_device *obd);
 int target_queue_final_reply(struct ptlrpc_request *req, int rc);
+void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id);
 
 /* client.c */
-int client_obd_connect(struct lustre_handle *conn, struct obd_device *obd,
-                       struct obd_uuid *cluuid, struct recovd_obd *recovd,
-                       ptlrpc_recovery_cb_t recover);
-int client_obd_disconnect(struct lustre_handle *conn);
+
 int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf);
 int client_sanobd_setup(struct obd_device *obddev, obd_count len, void *buf);
-int client_obd_cleanup(struct obd_device * obddev);
+int client_obd_cleanup(struct obd_device * obddev, int force, int failover);
 struct client_obd *client_conn2cli(struct lustre_handle *conn);
 struct obd_device *client_tgtuuid2obd(struct obd_uuid *tgtuuid);
 
+/* It is important that och_fh remain the first item in this structure: that
+ * way, we don't have to re-pack the obdo's inline data before we send it to
+ * the server, we can just send the whole struct unaltered. */
+struct obd_client_handle {
+        struct lustre_handle och_fh;
+        struct ptlrpc_request *och_req;
+        __u32 och_magic;
+};
+#define OBD_CLIENT_HANDLE_MAGIC 0xd15ea5ed
+
 /* statfs_pack.c */
 int obd_self_statfs(struct obd_device *dev, struct statfs *sfs);
 
@@ -99,45 +108,74 @@ void l_lock(struct lustre_lock *);
 void l_unlock(struct lustre_lock *);
 int l_has_lock(struct lustre_lock *);
 
-#define CB_PHASE_START   12
-#define CB_PHASE_FINISH  13
-
-/* This list head doesn't need to be locked, because it's only manipulated by
- * one thread at a time. */
-struct obd_brw_set {
-        struct list_head brw_desc_head; /* list of ptlrpc_bulk_desc */
-        wait_queue_head_t brw_waitq;
-        atomic_t brw_refcount;
-        atomic_t brw_desc_count;
-        int brw_flags;
+/* simple.c */
+struct obd_ucred {
+        __u32 ouc_fsuid;
+        __u32 ouc_fsgid;
+        __u32 ouc_cap;
+        __u32 ouc_suppgid1;
+        __u32 ouc_suppgid2;
+};
 
-        int (*brw_callback)(struct obd_brw_set *, int phase);
+#define OBD_RUN_CTXT_MAGIC      0xC0FFEEAA
+#define OBD_CTXT_DEBUG          /* development-only debugging */
+struct obd_run_ctxt {
+        struct vfsmount *pwdmnt;
+        struct dentry   *pwd;
+        mm_segment_t     fs;
+        struct obd_ucred ouc;
+        int              ngroups;
+#ifdef OBD_CTXT_DEBUG
+        __u32            magic;
+#endif
 };
 
-/* simple.c */
-struct obd_run_ctxt;
-struct obd_ucred;
+
+#ifdef OBD_CTXT_DEBUG
+#define OBD_SET_CTXT_MAGIC(ctxt) (ctxt)->magic = OBD_RUN_CTXT_MAGIC
+#else
+#define OBD_SET_CTXT_MAGIC(ctxt) do {} while(0)
+#endif
+
+#ifdef __KERNEL__
+
 void push_ctxt(struct obd_run_ctxt *save, struct obd_run_ctxt *new_ctx,
                struct obd_ucred *cred);
 void pop_ctxt(struct obd_run_ctxt *saved, struct obd_run_ctxt *new_ctx,
               struct obd_ucred *cred);
 struct dentry *simple_mkdir(struct dentry *dir, char *name, int mode);
 struct dentry *simple_mknod(struct dentry *dir, char *name, int mode);
-int lustre_fread(struct file *file, char *str, int len, loff_t *off);
-int lustre_fwrite(struct file *file, const char *str, int len, loff_t *off);
+int lustre_fread(struct file *file, void *buf, int len, loff_t *off);
+int lustre_fwrite(struct file *file, const void *buf, int len, loff_t *off);
 int lustre_fsync(struct file *file);
 
-#ifdef __KERNEL__
-
 static inline void l_dput(struct dentry *de)
 {
         if (!de || IS_ERR(de))
                 return;
-        shrink_dcache_parent(de);
+        //shrink_dcache_parent(de);
         LASSERT(atomic_read(&de->d_count) > 0);
         dput(de);
 }
 
+/* We need to hold the inode semaphore over the dcache lookup itself, or we
+ * run the risk of entering the filesystem lookup path concurrently on SMP
+ * systems, and instantiating two inodes for the same entry.  We still
+ * protect against concurrent addition/removal races with the DLM locking.
+ */
+static inline struct dentry *ll_lookup_one_len(char *fid_name,
+                                               struct dentry *dparent,
+                                               int fid_namelen)
+{
+        struct dentry *dchild;
+
+        down(&dparent->d_inode->i_sem);
+        dchild = lookup_one_len(fid_name, dparent, fid_namelen);
+        up(&dparent->d_inode->i_sem);
+
+        return dchild;
+}
+
 static inline void ll_sleep(int t)
 {
         set_current_state(TASK_INTERRUPTIBLE);
@@ -146,17 +184,10 @@ static inline void ll_sleep(int t)
 }
 #endif
 
-/* FIXME: This needs to validate pointers and cookies */
-static inline void *lustre_handle2object(struct lustre_handle *handle)
-{
-        if (handle)
-                return (void *)(unsigned long)(handle->addr);
-        return NULL;
-}
-
-static inline void ldlm_object2handle(void *object, struct lustre_handle *handle)
+#define LL_FID_NAMELEN         (16 + 1 + 8 + 1)
+static inline int ll_fid2str(char *str, __u64 id, __u32 generation)
 {
-        handle->addr = (__u64)(unsigned long)object;
+        return sprintf(str, "%llx:%08x", (unsigned long long)id, generation);
 }
 
 #include <linux/portals_lib.h>
@@ -170,7 +201,6 @@ struct obd_ioctl_data {
         uint32_t ioc_len;
         uint32_t ioc_version;
 
-        uint64_t ioc_addr;
         uint64_t ioc_cookie;
         uint32_t ioc_conn1;
         uint32_t ioc_conn2;
@@ -368,6 +398,8 @@ static inline int obd_ioctl_unpack(struct obd_ioctl_data *data, char *pbuf,
 
 #include <linux/obd_support.h>
 
+#define OBD_MAX_IOCTL_BUFFER 8192
+
 /* buffer MUST be at least the size of obd_ioctl_hdr */
 static inline int obd_ioctl_getdata(char **buf, int *len, void *arg)
 {
@@ -383,12 +415,13 @@ static inline int obd_ioctl_getdata(char **buf, int *len, void *arg)
         }
 
         if (hdr.ioc_version != OBD_IOCTL_VERSION) {
-                printk("OBD: version mismatch kernel vs application\n");
+                CERROR("Version mismatch kernel vs application\n");
                 return -EINVAL;
         }
 
-        if (hdr.ioc_len > 8192) {
-                printk("OBD: user buffer exceeds 8192 max buffer\n");
+        if (hdr.ioc_len > OBD_MAX_IOCTL_BUFFER) {
+                CERROR("User buffer len %d exceeds %d max buffer\n",
+                       hdr.ioc_len, OBD_MAX_IOCTL_BUFFER);
                 return -EINVAL;
         }
 
@@ -397,8 +430,10 @@ static inline int obd_ioctl_getdata(char **buf, int *len, void *arg)
                 return -EINVAL;
         }
 
-        OBD_ALLOC(*buf, hdr.ioc_len);
-        if (!*buf) {
+        /* XXX allocate this more intelligently, using kmalloc when
+         * appropriate */
+        OBD_VMALLOC(*buf, hdr.ioc_len);
+        if (*buf == NULL) {
                 CERROR("Cannot allocate control buffer of len %d\n",
                        hdr.ioc_len);
                 RETURN(-EINVAL);
@@ -413,7 +448,7 @@ static inline int obd_ioctl_getdata(char **buf, int *len, void *arg)
         }
 
         if (obd_ioctl_is_invalid(data)) {
-                printk("OBD: ioctl not correctly formatted\n");
+                CERROR("ioctl not correctly formatted\n");
                 return -EINVAL;
         }
 
@@ -436,6 +471,15 @@ static inline int obd_ioctl_getdata(char **buf, int *len, void *arg)
         return 0;
 }
 
+static inline void obd_ioctl_freedata(char *buf, int len)
+{
+        ENTRY;
+
+        OBD_VFREE(buf, len);
+        EXIT;
+        return;
+}
+
 #define OBD_IOC_CREATE                 _IOR ('f', 101, long)
 #define OBD_IOC_SETUP                  _IOW ('f', 102, long)
 #define OBD_IOC_CLEANUP                _IO  ('f', 103      )
@@ -467,19 +511,18 @@ static inline int obd_ioctl_getdata(char **buf, int *len, void *arg)
 #define OBD_IOC_LIST                   _IOWR('f', 129, long)
 #define OBD_IOC_UUID2DEV               _IOWR('f', 130, long)
 
-#define OBD_IOC_RECOVD_NEWCONN         _IOWR('f', 131, long)
-#define OBD_IOC_LOV_SET_CONFIG         _IOWR('f', 132, long)
-#define OBD_IOC_LOV_GET_CONFIG         _IOWR('f', 133, long)
+#define OBD_IOC_LOV_SET_CONFIG         _IOWR('f', 131, long)
+#define OBD_IOC_LOV_GET_CONFIG         _IOWR('f', 132, long)
 #define OBD_IOC_LOV_CONFIG             OBD_IOC_LOV_SET_CONFIG
+#define OBD_IOC_CLIENT_RECOVER         _IOW ('f', 133, long)
 
 #define OBD_IOC_OPEN                   _IOWR('f', 134, long)
 #define OBD_IOC_CLOSE                  _IOWR('f', 135, long)
 
-#define OBD_IOC_RECOVD_FAILCONN        _IOWR('f', 136, long)
-
 #define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 139      )
 #define OBD_IOC_NO_TRANSNO             _IOW ('f', 140, long)
 #define OBD_IOC_SET_READONLY           _IOW ('f', 141, long)
+#define OBD_IOC_ABORT_RECOVERY         _IOR ('f', 142, long)
 
 #define OBD_GET_VERSION                _IOWR ('f', 144, long)
 
@@ -487,11 +530,20 @@ static inline int obd_ioctl_getdata(char **buf, int *len, void *arg)
 #define OBD_IOC_DEL_UUID               _IOWR ('f', 146, long)
 #define OBD_IOC_CLOSE_UUID             _IOWR ('f', 147, long)
 
+#define OBD_IOC_MOUNTOPT               _IOWR('f', 170, long)
+
 #define ECHO_IOC_GET_STRIPE            _IOWR('f', 200, long)
 #define ECHO_IOC_SET_STRIPE            _IOWR('f', 201, long)
 #define ECHO_IOC_ENQUEUE               _IOWR('f', 202, long)
 #define ECHO_IOC_CANCEL                _IOWR('f', 203, long)
 
+/* XXX _IOWR('f', 250, long) has been defined in
+ * portals/include/linux/kp30.h for debug, don't use it
+ */
+
+/* Until such time as we get_info the per-stripe maximum from the OST,
+ * we define this to be 2T - 4k, which is the ext3 maxbytes. */
+#define LUSTRE_STRIPE_MAXBYTES 0x1fffffff000ULL
 
 #define CHECKSUM_BULK 0
 
@@ -507,8 +559,6 @@ static inline void ost_checksum(__u64 *cksum, void *addr, int len)
 
         *cksum = (*cksum << 2) + sum;
 }
-#else
-#define ost_checksum(cksum, addr, len) do {} while (0)
 #endif
 
 /*
@@ -551,7 +601,7 @@ struct l_wait_info {
         long   lwi_timeout;
         int  (*lwi_on_timeout)(void *);
         long   lwi_signals;
-        int  (*lwi_on_signal)(void *); /* XXX return is ignored for now */
+        void (*lwi_on_signal)(void *);
         void  *lwi_cb_data;
 };
 
@@ -587,11 +637,11 @@ static inline sigset_t l_w_e_set_sigs(int sigs)
         sigset_t old;
         unsigned long irqflags;
 
-        spin_lock_irqsave(&current->sigmask_lock, irqflags);
+        SIGNAL_MASK_LOCK(current, irqflags);
         old = current->blocked;
         siginitsetinv(&current->blocked, sigs);
-        recalc_sigpending(current);
-        spin_unlock_irqrestore(&current->sigmask_lock, irqflags);
+        RECALC_SIGPENDING;
+        SIGNAL_MASK_UNLOCK(current, irqflags);
 
         return old;
 }
@@ -639,10 +689,10 @@ do {                                                                           \
             }                                                                  \
         }                                                                      \
                                                                                \
-        spin_lock_irqsave(&current->sigmask_lock, irqflags);                   \
+        SIGNAL_MASK_LOCK(current, irqflags);                                   \
         current->blocked = blocked;                                            \
-        recalc_sigpending(current);                                            \
-        spin_unlock_irqrestore(&current->sigmask_lock, irqflags);              \
+        RECALC_SIGPENDING;                                                     \
+        SIGNAL_MASK_UNLOCK(current, irqflags);                                 \
                                                                                \
         current->state = TASK_RUNNING;                                         \
         remove_wait_queue(&wq, &__wait);                                       \
@@ -656,6 +706,11 @@ do {                                                                           \
                 __l_wait_event(wq, condition, __info, __ret);                  \
         __ret;                                                                 \
 })
+#else
+#define l_wait_event(wq, condition, info)       \
+({                                              \
+        0;                                      \
+})
 #endif /* __KERNEL__ */
 
 #endif /* _LUSTRE_LIB_H */