-/*
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
* linux/fs/ext2/file.c
*
* This code is issued under the GNU General Public License.
#include <linux/pagemap.h>
#include <linux/smp_lock.h>
+#define DEBUG_SUBSYSTEM S_LLITE
+
#include <linux/obd_support.h>
-#include <linux/lustre_light.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);
+
+static int ll_file_open(struct inode *inode, struct file *file)
+{
+ int rc;
+ struct ptlrpc_request *req;
+ struct ll_file_data *fd;
+ struct obdo *oa;
+ struct ll_sb_info *sbi = ll_i2sbi(inode);
+ ENTRY;
+
+ if (file->private_data)
+ LBUG();
+
+ 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, 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);
+ if (rc) {
+ if (rc > 0)
+ rc = -rc;
+ GOTO(out, rc);
+ }
+
+ oa = ll_oa_from_inode(inode, (OBD_MD_FLMODE | OBD_MD_FLID));
+ if (oa == NULL)
+ LBUG();
+ 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);
+ }
+
+ file->private_data = fd;
+
+ EXIT;
+ out:
+ if (rc && fd) {
+ kmem_cache_free(ll_file_data_slab, fd);
+ file->private_data = NULL;
+ }
+
+ return rc;
+}
+
+static int ll_file_release(struct inode *inode, struct file *file)
+{
+ int rc;
+ struct ptlrpc_request *req;
+ struct ll_file_data *fd;
+ struct obdo *oa;
+ struct ll_sb_info *sbi = ll_i2sbi(inode);
+ struct iattr iattr;
+
+ ENTRY;
+
+ fd = (struct ll_file_data *)file->private_data;
+ if (!fd || !fd->fd_mdshandle) {
+ LBUG();
+ GOTO(out, rc = -EINVAL);
+ }
+
+ oa = ll_oa_from_inode(inode, (OBD_MD_FLMODE | OBD_MD_FLID));
+ if (oa == NULL)
+ LBUG();
+ rc = obd_close(ll_i2obdconn(inode), oa);
+ obdo_free(oa);
+ if (rc) {
+ if (rc > 0)
+ rc = -rc;
+ GOTO(out, 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 = mdc_close(&sbi->ll_mds_client, inode->i_ino, S_IFREG,
+ fd->fd_mdshandle, &req);
+ ptlrpc_free_req(req);
+ if (rc) {
+ if (rc > 0)
+ rc = -rc;
+ GOTO(out, rc);
+ }
+ EXIT;
+
+ out:
+ if (!rc && fd) {
+ kmem_cache_free(ll_file_data_slab, fd);
+ file->private_data = NULL;
+ }
+ return rc;
+}
+
static inline void ll_remove_suid(struct inode *inode)
{
mode &= inode->i_mode;
if (mode && !capable(CAP_FSETID)) {
inode->i_mode &= ~mode;
- // XXX careful here - we cannot change the size
+ // XXX careful here - we cannot change the size
}
}
+
/*
* Write to a file (through the page cache).
*/
retval = generic_file_write(file, buf, count, ppos);
CDEBUG(D_INFO, "Wrote %d\n", retval);
- /* update mtime/ctime/atime here, NOT size */
+ /* update mtime/ctime/atime here, NOT size */
if (retval > 0) {
- struct iattr attr;
- attr.ia_valid = ATTR_MTIME | ATTR_CTIME | ATTR_ATIME;
- attr.ia_mtime = attr.ia_ctime = attr.ia_atime =
- CURRENT_TIME;
+ struct iattr attr;
+ attr.ia_valid = ATTR_MTIME | ATTR_CTIME | ATTR_ATIME;
+ attr.ia_mtime = attr.ia_ctime = attr.ia_atime =
+ CURRENT_TIME;
ll_setattr(file->f_dentry, &attr);
}
EXIT;
call setattr */
int ll_fsync(struct file *file, struct dentry *dentry, int data)
{
- return 0;
+ return 0;
}
struct file_operations ll_file_operations = {
read: generic_file_read,
write: ll_file_write,
+ open: ll_file_open,
+ release: ll_file_release,
mmap: generic_file_mmap,
- fsync: NULL
+ fsync: NULL
};
struct inode_operations ll_file_inode_operations = {
truncate: ll_truncate,
- setattr: ll_setattr
+ setattr: ll_setattr
};