Whamcloud - gitweb
Landing the ldlm_testing branch; now the only difference is that the locking
[fs/lustre-release.git] / lustre / llite / file.c
index b41e50c..4be688a 100644 (file)
  *      (jj@sunsite.ms.mff.cuni.cz)
  */
 
-#include <asm/uaccess.h>
-#include <asm/system.h>
-
-#include <linux/errno.h>
-#include <linux/fs.h>
-#include <linux/fcntl.h>
-#include <linux/sched.h>
-#include <linux/stat.h>
-#include <linux/locks.h>
-#include <linux/mm.h>
-#include <linux/pagemap.h>
-#include <linux/smp_lock.h>
-
 #define DEBUG_SUBSYSTEM S_LLITE
 
-#include <linux/obd_support.h>
+#include <linux/lustre_dlm.h>
 #include <linux/lustre_lite.h>
 
 int ll_inode_setattr(struct inode *inode, struct iattr *attr, int do_trunc);
 extern int ll_setattr(struct dentry *de, struct iattr *attr);
-extern inline struct obdo * ll_oa_from_inode(struct inode *inode, int valid);
+extern inline struct obdo * ll_oa_from_inode(struct inode *inode,
+                                             unsigned long valid);
 
 static int ll_file_open(struct inode *inode, struct file *file)
 {
-        int rc; 
+        int rc;
         struct ptlrpc_request *req = NULL;
         struct ll_file_data *fd;
         struct obdo *oa;
         struct ll_sb_info *sbi = ll_i2sbi(inode);
         ENTRY;
 
-        if (file->private_data) 
+        if (file->private_data)
                 LBUG();
 
-        fd = kmem_cache_alloc(ll_file_data_slab, SLAB_KERNEL); 
+        fd = kmem_cache_alloc(ll_file_data_slab, SLAB_KERNEL);
         if (!fd)
                 GOTO(out, rc = -ENOMEM);
         memset(fd, 0, sizeof(*fd));
 
         rc = mdc_open(&sbi->ll_mds_client, sbi->ll_mds_conn, inode->i_ino,
-                      S_IFREG, file->f_flags, &fd->fd_mdshandle, &req); 
-        if (!fd->fd_mdshandle)
-                CERROR("mdc_open didn't assign fd_mdshandle\n");
-
-        ptlrpc_free_req(req);
+                      S_IFREG, file->f_flags, &fd->fd_mdshandle, &req);
+        fd->fd_req = req;
+        ptlrpc_req_finished(req);
         if (rc) {
                 if (rc > 0) 
                         rc = -rc;
                 GOTO(out, rc);
         }
+        if (!fd->fd_mdshandle)
+                CERROR("mdc_open didn't assign fd_mdshandle\n");
+        
 
         oa = ll_oa_from_inode(inode, (OBD_MD_FLMODE | OBD_MD_FLID));
         if (oa == NULL)
                 LBUG();
-        rc = obd_open(ll_i2obdconn(inode), oa); 
+        rc = obd_open(ll_i2obdconn(inode), oa);
         obdo_free(oa);
         if (rc) {
                 /* XXX: Need to do mdc_close here! */
-                if (rc > 0) 
-                        rc = -rc;
-                GOTO(out, rc);
+                GOTO(out, rc = abs(rc));
         }
 
         file->private_data = fd;
 
-        EXIT; 
+        EXIT;
  out:
         if (rc && fd) {
-                kmem_cache_free(ll_file_data_slab, fd); 
+                kmem_cache_free(ll_file_data_slab, fd);
                 file->private_data = NULL;
         }
 
@@ -110,7 +97,7 @@ static int ll_file_release(struct inode *inode, struct file *file)
         ENTRY;
 
         fd = (struct ll_file_data *)file->private_data;
-        if (!fd || !fd->fd_mdshandle) { 
+        if (!fd || !fd->fd_mdshandle) {
                 LBUG();
                 GOTO(out, rc = -EINVAL);
         }
@@ -118,35 +105,34 @@ static int ll_file_release(struct inode *inode, struct file *file)
         oa = ll_oa_from_inode(inode, (OBD_MD_FLMODE | OBD_MD_FLID));
         if (oa == NULL)
                 LBUG();
-        rc = obd_close(ll_i2obdconn(inode), oa); 
+        rc = obd_close(ll_i2obdconn(inode), oa);
         obdo_free(oa);
-        if (rc) { 
-                if (rc > 0) 
-                        rc = -rc;
-                GOTO(out, rc);
-        }
+        if (rc)
+                GOTO(out, abs(rc));
 
         iattr.ia_valid = ATTR_SIZE;
         iattr.ia_size = inode->i_size;
         rc = ll_inode_setattr(inode, &iattr, 0);
         if (rc) {
                 CERROR("failed - %d.\n", rc);
-                rc = -EIO;
+                rc = -EIO; /* XXX - GOTO(out)? -phil */
         }
 
         rc = mdc_close(&sbi->ll_mds_client, sbi->ll_mds_conn, inode->i_ino,
                        S_IFREG, fd->fd_mdshandle, &req);
-        ptlrpc_free_req(req);
+        ptlrpc_req_finished(req);
         if (rc) { 
                 if (rc > 0) 
                         rc = -rc;
                 GOTO(out, rc);
         }
+        ptlrpc_free_req(fd->fd_req);
+
         EXIT; 
 
  out:
-        if (!rc && fd) { 
-                kmem_cache_free(ll_file_data_slab, fd); 
+        if (!rc && fd) {
+                kmem_cache_free(ll_file_data_slab, fd);
                 file->private_data = NULL;
         }
         return rc;
@@ -168,6 +154,53 @@ static inline void ll_remove_suid(struct inode *inode)
         }
 }
 
+static ssize_t ll_file_read(struct file *filp, char *buf, size_t count,
+                            loff_t *ppos)
+{
+        struct inode *inode = filp->f_dentry->d_inode;
+#if 0
+        struct ll_sb_info *sbi = ll_i2sbi(inode);
+        struct ldlm_extent extent;
+        struct ldlm_handle lockh;
+        __u64 res_id[RES_NAME_SIZE] = {inode->i_ino};
+        int flags = 0;
+        ldlm_error_t err;
+#endif
+        ssize_t retval;
+        ENTRY;
+
+#if 0
+        extent.start = *ppos;
+        extent.end = *ppos + count;
+        CDEBUG(D_INFO, "Locking inode %ld, start %Lu end %Lu\n",
+               inode->i_ino, extent.start, extent.end);
+
+        err = obd_enqueue(&sbi->ll_conn, sbi->ll_namespace, NULL, res_id,
+                          LDLM_EXTENT, &extent, LCK_PR, &flags, inode,
+                          sizeof(*inode), &lockh);
+        if (err != ELDLM_OK)
+                CERROR("lock enqueue: err: %d\n", err);
+        ldlm_lock_dump((void *)(unsigned long)lockh.addr);
+#endif
+
+        CDEBUG(D_INFO, "Reading inode %ld, %d bytes, offset %Ld\n",
+               inode->i_ino, count, *ppos);
+        retval = generic_file_read(filp, buf, count, ppos);
+        if (retval > 0) {
+                struct iattr attr;
+                attr.ia_valid = ATTR_ATIME;
+                attr.ia_atime = CURRENT_TIME;
+                ll_setattr(filp->f_dentry, &attr);
+        }
+
+#if 0
+        err = obd_cancel(&sbi->ll_conn, LCK_PR, &lockh);
+        if (err != ELDLM_OK)
+                CERROR("lock cancel: err: %d\n", err);
+#endif
+
+        RETURN(retval);
+}
 
 /*
  * Write to a file (through the page cache).
@@ -175,12 +208,36 @@ static inline void ll_remove_suid(struct inode *inode)
 static ssize_t
 ll_file_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
 {
+        struct inode *inode = file->f_dentry->d_inode;
+#if 0
+        struct ll_sb_info *sbi = ll_i2sbi(inode);
+        struct ldlm_extent extent;
+        struct ldlm_handle lockh;
+        __u64 res_id[RES_NAME_SIZE] = {inode->i_ino};
+        int flags = 0;
+        ldlm_error_t err;
+#endif
         ssize_t retval;
+        ENTRY;
+
+#if 0
+        extent.start = *ppos;
+        extent.end = *ppos + count;
+        CDEBUG(D_INFO, "Locking inode %ld, start %Lu end %Lu\n",
+               inode->i_ino, extent.start, extent.end);
+
+        err = obd_enqueue(&sbi->ll_conn, sbi->ll_namespace, NULL, res_id,
+                          LDLM_EXTENT, &extent, LCK_PW, &flags, inode,
+                          sizeof(*inode), &lockh);
+        if (err != ELDLM_OK)
+                CERROR("lock enqueue: err: %d\n", err);
+        ldlm_lock_dump((void *)(unsigned long)lockh.addr);
+#endif
+
         CDEBUG(D_INFO, "Writing inode %ld, %ld bytes, offset %Ld\n",
-               file->f_dentry->d_inode->i_ino, (long)count, *ppos);
+               inode->i_ino, (long)count, *ppos);
 
         retval = generic_file_write(file, buf, count, ppos);
-        CDEBUG(D_INFO, "Wrote %ld\n", (long)retval);
 
         /* update mtime/ctime/atime here, NOT size */
         if (retval > 0) {
@@ -190,20 +247,25 @@ ll_file_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
                         CURRENT_TIME;
                 ll_setattr(file->f_dentry, &attr);
         }
-        EXIT;
-        return retval;
-}
 
+#if 0
+        err = obd_cancel(&sbi->ll_conn, LCK_PW, &lockh);
+        if (err != ELDLM_OK)
+                CERROR("lock cancel: err: %d\n", err);
+#endif
+
+        RETURN(retval);
+}
 
 /* XXX this does not need to do anything for data, it _does_ need to
-   call setattr */ 
+   call setattr */
 int ll_fsync(struct file *file, struct dentry *dentry, int data)
 {
         return 0;
 }
 
 struct file_operations ll_file_operations = {
-        read: generic_file_read,
+        read: ll_file_read,
         write: ll_file_write,
         open: ll_file_open,
         release: ll_file_release,
@@ -211,9 +273,7 @@ struct file_operations ll_file_operations = {
         fsync: NULL
 };
 
-
 struct inode_operations ll_file_inode_operations = {
         truncate: ll_truncate,
         setattr: ll_setattr
 };
-