Whamcloud - gitweb
b=24037 Changes of 2.6.32 kernel.
[fs/lustre-release.git] / lustre / lvfs / fsfilt_ext3.c
index 82f8879..c89de20 100644 (file)
 #ifdef HAVE_QUOTAIO_V1_H
 # include <linux/quotaio_v1.h>
 # include <linux/quotaio_v2.h>
+#elif defined(HAVE_FS_QUOTA_QUOTAIO_V1_H)
+# include <quota/quotaio_v1.h>
+# include <quota/quotaio_v2.h>
+# include <quota/quota_tree.h>
+# define V2_DQTREEOFF    QT_TREEOFF
 #else
 # include <quotaio_v1.h>
 # include <quotaio_v2.h>
@@ -82,13 +87,11 @@ extern int ext3_xattr_set_handle(handle_t *, struct inode *, int, const char *,
 #include <linux/lustre_compat25.h>
 #include <linux/lprocfs_status.h>
 
-#ifdef EXT3_MULTIBLOCK_ALLOCATOR
 #ifdef HAVE_EXT4_LDISKFS
 #include <ext4/ext4_extents.h>
 #else
 #include <linux/ext3_extents.h>
 #endif
-#endif
 
 #include "lustre_quota_fmt.h"
 
@@ -107,6 +110,15 @@ extern int ext3_xattr_set_handle(handle_t *, struct inode *, int, const char *,
 #define FSFILT_SINGLEDATA_TRANS_BLOCKS(sb) EXT3_SINGLEDATA_TRANS_BLOCKS
 #endif
 
+#ifdef EXT_INSERT_EXTENT_WITH_5ARGS
+#define fsfilt_ext3_ext_insert_extent(handle, inode, path, newext, flag) \
+               ext3_ext_insert_extent(handle, inode, path, newext, flag)
+#else
+#define fsfilt_ext3_ext_insert_extent(handle, inode, path, newext, flag) \
+               ext3_ext_insert_extent(handle, inode, path, newext)
+#endif
+
+
 static cfs_mem_cache_t *fcb_cache;
 
 struct fsfilt_cb_data {
@@ -622,9 +634,21 @@ static int fsfilt_ext3_iocontrol(struct inode *inode, struct file *file,
         ENTRY;
 
         /* FIXME: Can't do this because of nested transaction deadlock */
-        if (cmd == EXT3_IOC_SETFLAGS && (*(int *)arg) & EXT3_JOURNAL_DATA_FL) {
-                CERROR("can't set data journal flag on file\n");
-                RETURN(-EPERM);
+        if (cmd == EXT3_IOC_SETFLAGS) {
+                /* We can't enable data journaling on OST objects, because
+                * this forces the transaction to be closed in order to
+                * flush the journal, but the caller will already have a
+                * compound transaction open to update the last_rcvd file,
+                * and this thread would deadlock trying to set the flag. */
+                if ((*(int *)arg) & EXT3_JOURNAL_DATA_FL) {
+                        CERROR("can't set data journal flag on file\n");
+                        RETURN(-EPERM);
+                }
+                /* Because the MDS does not see the EXTENTS_FL set on the
+                 * OST objects, mask this flag into all set flags.  It is
+                 * not legal to clear this flag in any case, so we are not
+                 * changing the functionality by doing this.  b=22911 */
+                *(int *)arg |= EXT3_I(inode)->i_flags & EXT3_EXTENTS_FL;
         }
 
 #ifdef HAVE_EXT4_LDISKFS
@@ -805,26 +829,26 @@ static int fsfilt_ext3_sync(struct super_block *sb)
         return ext3_force_commit(sb);
 }
 
-#if defined(EXT3_MULTIBLOCK_ALLOCATOR) && (!defined(EXT3_EXT_CACHE_NO) || defined(EXT_CACHE_MARK))
-#warning "kernel code has old extents/mballoc patch, disabling"
-#undef EXT3_MULTIBLOCK_ALLOCATOR
-#endif
 #ifndef EXT3_EXTENTS_FL
 #define EXT3_EXTENTS_FL                 0x00080000 /* Inode uses extents */
 #endif
 
-#ifdef EXT3_MULTIBLOCK_ALLOCATOR
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17))
-#define fsfilt_up_truncate_sem(inode)  up(&EXT3_I(inode)->truncate_sem);
-#define fsfilt_down_truncate_sem(inode)  down(&EXT3_I(inode)->truncate_sem);
-#else
-#ifdef HAVE_EXT4_LDISKFS
-#define fsfilt_up_truncate_sem(inode) up_write((&EXT4_I(inode)->i_data_sem));
-#define fsfilt_down_truncate_sem(inode) down_write((&EXT4_I(inode)->i_data_sem));
+# define fsfilt_up_truncate_sem(inode)  up(&LDISKFS_I(inode)->truncate_sem);
+# define fsfilt_down_truncate_sem(inode)  down(&LDISKFS_I(inode)->truncate_sem);
 #else
-#define fsfilt_up_truncate_sem(inode)  mutex_unlock(&EXT3_I(inode)->truncate_mutex);
-#define fsfilt_down_truncate_sem(inode)  mutex_lock(&EXT3_I(inode)->truncate_mutex);
-#endif
+# ifdef HAVE_EXT4_LDISKFS
+#  ifdef WALK_SPACE_HAS_DATA_SEM /* We only use it in fsfilt_map_nblocks() for now */
+#   define fsfilt_up_truncate_sem(inode) do{ }while(0)
+#   define fsfilt_down_truncate_sem(inode) do{ }while(0)
+#  else
+#   define fsfilt_up_truncate_sem(inode) up_write((&EXT4_I(inode)->i_data_sem))
+#   define fsfilt_down_truncate_sem(inode) down_write((&EXT4_I(inode)->i_data_sem))
+#  endif
+# else
+#  define fsfilt_up_truncate_sem(inode)  mutex_unlock(&EXT3_I(inode)->truncate_mutex)
+#  define fsfilt_down_truncate_sem(inode)  mutex_lock(&EXT3_I(inode)->truncate_mutex)
+# endif
 #endif
 
 #ifndef EXT_ASSERT
@@ -850,6 +874,14 @@ static int fsfilt_ext3_sync(struct super_block *sb)
                         ext3_ext_walk_space(tree, block, num, cb);
 #endif
 
+#ifdef EXT_INSERT_EXTENT_WITH_5ARGS
+#define fsfilt_ext3_ext_insert_extent(handle, inode, path, newext, flag) \
+               ext3_ext_insert_extent(handle, inode, path, newext, flag)
+#else
+#define fsfilt_ext3_ext_insert_extent(handle, inode, path, newext, flag) \
+               ext3_ext_insert_extent(handle, inode, path, newext)
+#endif
+
 #include <linux/lustre_version.h>
 
 struct bpointers {
@@ -1025,7 +1057,7 @@ static int ext3_ext_new_extent_cb(struct ext3_ext_base *base,
         nex.ee_block = cpu_to_le32(cex->ec_block);
         ext3_ext_store_pblock(&nex, pblock);
         nex.ee_len = cpu_to_le16(count);
-        err = ext3_ext_insert_extent(handle, base, path, &nex);
+        err = fsfilt_ext3_ext_insert_extent(handle, base, path, &nex, 0);
         if (err) {
                 /* free data blocks we just allocated */
                 /* not a good idea to call discard here directly,
@@ -1172,7 +1204,6 @@ int fsfilt_ext3_map_ext_inode_pages(struct inode *inode, struct page **page,
 cleanup:
         return rc;
 }
-#endif /* EXT3_MULTIBLOCK_ALLOCATOR */
 
 extern int ext3_map_inode_page(struct inode *inode, struct page *page,
                                unsigned long *blocks, int *created, int create);
@@ -1204,13 +1235,12 @@ int fsfilt_ext3_map_inode_pages(struct inode *inode, struct page **page,
                                 cfs_semaphore_t *optional_sem)
 {
         int rc;
-#ifdef EXT3_MULTIBLOCK_ALLOCATOR
+
         if (EXT3_I(inode)->i_flags & EXT3_EXTENTS_FL) {
                 rc = fsfilt_ext3_map_ext_inode_pages(inode, page, pages,
                                                      blocks, created, create);
                 return rc;
         }
-#endif
         if (optional_sem != NULL)
                 cfs_down(optional_sem);
         rc = fsfilt_ext3_map_bm_inode_pages(inode, page, pages, blocks,
@@ -1463,7 +1493,7 @@ static int fsfilt_ext3_quotactl(struct super_block *sb,
                                 struct obd_quotactl *oqc)
 {
         int i, rc = 0, error = 0;
-        struct quotactl_ops *qcop;
+        const struct quotactl_ops *qcop;
         struct if_dqinfo *info;
         struct if_dqblk *dqblk;
         ENTRY;
@@ -1585,8 +1615,8 @@ struct chk_dqblk{
         qsize_t                 dqb_ihardlimit;  /** inode hard limit */
         qsize_t                 dqb_isoftlimit;  /** inode soft limit */
         qsize_t                 dqb_curinodes;   /** current inodes */
-        __u64                   dqb_btime;       /** block grace time */
-        __u64                   dqb_itime;       /** inode grace time */
+        obd_time                dqb_btime;       /** block grace time */
+        obd_time                dqb_itime;       /** inode grace time */
         __u32                   dqb_valid;       /** flag for above fields */
 };
 
@@ -1819,7 +1849,7 @@ static int v3_write_dqinfo(struct file *f, int type, struct if_dqinfo *info)
 static int v3_write_dqheader(struct file *f, int type)
 {
         static const __u32 quota_magics[] = V2_INITQMAGICS;
-        static const __u32 quota_versions[] = V2_INITQVERSIONS_R1;
+        static const __u32 quota_versions[] = LUSTRE_INITQVERSIONS_V2;
         struct v2_disk_dqheader dqhead;
         loff_t offset = 0;
 
@@ -1863,7 +1893,7 @@ static int create_new_quota_files(struct qchk_ctxt *qctxt,
                         GOTO(out, rc = -EINVAL);
                 }
 
-                DQUOT_DROP(file->f_dentry->d_inode);
+                ll_vfs_dq_drop(file->f_dentry->d_inode);
 
                 rc = v3_write_dqheader(file, i);
                 if (rc) {
@@ -2004,14 +2034,27 @@ static int fsfilt_ext3_quotacheck(struct super_block *sb,
                         /* we don't really need to take the group lock here,
                          * but it may be useful if one day we support online
                          * quotacheck */
+#ifdef HAVE_EXT4_LDISKFS
+                        ext4_lock_group(sb, group);
+#else
                         spin_lock(sb_bgl_lock(sbi, group));
+#endif
                         if (desc->bg_flags & cpu_to_le16(EXT3_BG_INODE_UNINIT)) {
                                 /* no inode in use in this group, just skip it */
+#ifdef HAVE_EXT4_LDISKFS
+                                ext3_unlock_group(sb, group);
+#else
                                 spin_unlock(sb_bgl_lock(sbi, group));
+#endif
                                 continue;
                         }
+
                         used_count -= ext3_itable_unused_count(sb, desc);
+#ifdef HAVE_EXT4_LDISKFS
+                        ext3_unlock_group(sb, group);
+#else
                         spin_unlock(sb_bgl_lock(sbi, group));
+#endif
                 }
 
                 ino = group * sbi->s_inodes_per_group + 1;