linux-warning-reduction-20090318
[openafs.git] / src / afs / LINUX / osi_file.c
index 68e9ee3..5c80978 100644 (file)
@@ -23,7 +23,9 @@ RCSID
 #if defined(AFS_LINUX26_ENV)
 #include "h/namei.h"
 #endif
-
+#if !defined(HAVE_IGET)
+#include "h/exportfs.h"
+#endif
 
 afs_lock_t afs_xosi;           /* lock is for tvattr */
 extern struct osi_dev cacheDev;
@@ -34,13 +36,20 @@ extern struct super_block *afs_cacheSBp;
 
 #if defined(AFS_LINUX26_ENV) 
 void *
+#if defined(LINUX_USE_FH)
+osi_UFSOpen_fh(struct fid *fh, int fh_type)
+#else
 osi_UFSOpen(afs_int32 ainode)
+#endif
 {
     register struct osi_file *afile = NULL;
     extern int cacheDiskType;
     struct inode *tip = NULL;
     struct dentry *dp = NULL;
     struct file *filp = NULL;
+#if !defined(HAVE_IGET) || defined(LINUX_USE_FH)
+    struct fid fid;
+#endif
     AFS_STATCNT(osi_UFSOpen);
     if (cacheDiskType != AFS_FCACHE_TYPE_UFS) {
        osi_Panic("UFSOpen called for non-UFS cache\n");
@@ -55,27 +64,50 @@ osi_UFSOpen(afs_int32 ainode)
     AFS_GUNLOCK();
     if (!afile) {
        osi_Panic("osi_UFSOpen: Failed to allocate %d bytes for osi_file.\n",
-                 sizeof(struct osi_file));
+                 (int)sizeof(struct osi_file));
     }
     memset(afile, 0, sizeof(struct osi_file));
+#if defined(HAVE_IGET)
     tip = iget(afs_cacheSBp, (u_long) ainode);
     if (!tip)
        osi_Panic("Can't get inode %d\n", ainode);
-    tip->i_flags |= MS_NOATIME;        /* Disable updating access times. */
 
     dp = d_alloc_anon(tip);
+#else
+#if defined(LINUX_USE_FH)
+    dp = afs_cacheSBp->s_export_op->fh_to_dentry(afs_cacheSBp, fh, sizeof(struct fid), fh_type);
+#else
+    fid.i32.ino = ainode;
+    fid.i32.gen = 0;
+    dp = afs_cacheSBp->s_export_op->fh_to_dentry(afs_cacheSBp, &fid, sizeof(fid), FILEID_INO32_GEN);
+#endif
     if (!dp) 
-           osi_Panic("Can't get dentry for inode %d\n", ainode);          
+           osi_Panic("Can't get dentry\n");          
+    tip = dp->d_inode;
+#endif
+    tip->i_flags |= MS_NOATIME;        /* Disable updating access times. */
 
+#if defined(STRUCT_TASK_HAS_CRED)
+    filp = dentry_open(dp, mntget(afs_cacheMnt), O_RDWR, current_cred());
+#else
     filp = dentry_open(dp, mntget(afs_cacheMnt), O_RDWR);
+#endif
     if (IS_ERR(filp))
+#if defined(LINUX_USE_FH)
+       osi_Panic("Can't open file\n");
+#else
        osi_Panic("Can't open inode %d\n", ainode);
+#endif
     afile->filp = filp;
-    afile->size = FILE_INODE(filp)->i_size;
+    afile->size = i_size_read(FILE_INODE(filp));
     AFS_GLOCK();
     afile->offset = 0;
     afile->proc = (int (*)())0;
+#if defined(LINUX_USE_FH)
+    afile->inum = tip->i_ino;  /* for hint validity checking */
+#else
     afile->inum = ainode;      /* for hint validity checking */
+#endif
     return (void *)afile;
 }
 #else
@@ -122,7 +154,7 @@ osi_UFSOpen(afs_int32 ainode)
        code = filp->f_op->open(tip, filp);
     if (code)
        osi_Panic("Can't open inode %d\n", ainode);
-    afile->size = tip->i_size;
+    afile->size = i_size_read(tip);
     AFS_GLOCK();
     afile->offset = 0;
     afile->proc = (int (*)())0;
@@ -131,13 +163,30 @@ osi_UFSOpen(afs_int32 ainode)
 }
 #endif
 
+#if defined(LINUX_USE_FH)
+int
+osi_get_fh(struct dentry *dp, struct fid *fh, int *max_len) {
+    int fh_type;
+
+    if (dp->d_sb->s_export_op->encode_fh) {
+           fh_type = dp->d_sb->s_export_op->encode_fh(dp, (__u32 *)fh, max_len, 0);
+    } else {
+           fh_type = FILEID_INO32_GEN;
+           fh->i32.ino = dp->d_inode->i_ino;
+           fh->i32.gen = dp->d_inode->i_generation;
+    }
+    dput(dp);
+    return(fh_type);
+}
+#endif
+
 int
 afs_osi_Stat(register struct osi_file *afile, register struct osi_stat *astat)
 {
     register afs_int32 code;
     AFS_STATCNT(osi_Stat);
     MObtainWriteLock(&afs_xosi, 320);
-    astat->size = OSIFILE_INODE(afile)->i_size;
+    astat->size = i_size_read(OSIFILE_INODE(afile));
 #if defined(AFS_LINUX26_ENV)
     astat->mtime = OSIFILE_INODE(afile)->i_mtime.tv_sec;
     astat->atime = OSIFILE_INODE(afile)->i_atime.tv_sec;
@@ -227,7 +276,7 @@ osi_UFSTruncate(register struct osi_file *afile, afs_int32 asize)
     if (!code)
        truncate_inode_pages(&inode->i_data, asize);
 #else
-    inode->i_size = asize;
+    i_size_write(inode, asize);
     if (inode->i_sb->s_op && inode->i_sb->s_op->notify_change) {
        code = inode->i_sb->s_op->notify_change(&afile->dentry, &newattrs);
     }
@@ -349,8 +398,6 @@ afs_osi_MapStrategy(int (*aproc) (struct buf * bp), register struct buf *bp)
 void
 shutdown_osifile(void)
 {
-    extern int afs_cold_shutdown;
-
     AFS_STATCNT(shutdown_osifile);
     if (afs_cold_shutdown) {
        afs_osicred_initialized = 0;
@@ -362,6 +409,11 @@ int
 osi_InitCacheInfo(char *aname)
 {
     int code;
+#if defined(LINUX_USE_FH)
+    int max_len = sizeof(struct fid);
+#else
+    extern ino_t cacheInode;
+#endif
     struct dentry *dp;
     extern ino_t cacheInode;
     extern struct osi_dev cacheDev;
@@ -372,7 +424,17 @@ osi_InitCacheInfo(char *aname)
     if (code)
        return ENOENT;
 
+#if defined(LINUX_USE_FH)
+    if (dp->d_sb->s_export_op->encode_fh) {
+       cacheitems_fh_type = dp->d_sb->s_export_op->encode_fh(dp, (__u32 *)&cacheitems_fh, &max_len, 0);
+    } else {
+        cacheitems_fh_type = FILEID_INO32_GEN;
+       cacheitems_fh.i32.ino = dp->d_inode->i_ino;
+        cacheitems_fh.i32.gen = dp->d_inode->i_generation;
+    }
+#else
     cacheInode = dp->d_inode->i_ino;
+#endif
     cacheDev.dev = dp->d_inode->i_sb->s_dev;
     afs_fsfragsize = dp->d_inode->i_sb->s_blocksize - 1;
     afs_cacheSBp = dp->d_inode->i_sb;