DEVEL15-linux-warning-reduction-20090318
[openafs.git] / src / afs / LINUX / osi_file.c
index 6015358..5c80978 100644 (file)
@@ -36,14 +36,18 @@ 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)
+#if !defined(HAVE_IGET) || defined(LINUX_USE_FH)
     struct fid fid;
 #endif
     AFS_STATCNT(osi_UFSOpen);
@@ -60,7 +64,7 @@ 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)
@@ -70,24 +74,40 @@ osi_UFSOpen(afs_int32 ainode)
 
     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
@@ -134,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;
@@ -143,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;
@@ -239,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);
     }
@@ -372,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;
@@ -382,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;