From 819db3d5b3ca6522934fe6bf281a6c3ada4461ab Mon Sep 17 00:00:00 2001
From: bobijam <bobijam>
Date: Thu, 2 Aug 2007 02:26:36 +0000
Subject: [PATCH] Branch:b1_6 b=12606 i=shadow, nikita

Description: don't use GFP_* in generic Lustre code.
Details    : Use cfs_alloc_* functions and CFS_* flags for code portability.
---
 lustre/ChangeLog             | 6 ++++++
 lustre/include/liblustre.h   | 6 +++++-
 lustre/liblustre/dir.c       | 2 +-
 lustre/llite/file.c          | 4 ++--
 lustre/llite/lproc_llite.c   | 2 +-
 lustre/llite/rw.c            | 2 +-
 lustre/llite/rw26.c          | 2 +-
 lustre/llite/super25.c       | 4 ++--
 lustre/lov/lov_ea.c          | 2 +-
 lustre/lvfs/fsfilt_ext3.c    | 2 +-
 lustre/mds/handler.c         | 4 ++--
 lustre/obdclass/genops.c     | 4 ++--
 lustre/obdfilter/filter.c    | 2 +-
 lustre/ost/ost_handler.c     | 4 ++--
 lustre/ost/ost_internal.h    | 2 +-
 lustre/quota/quota_context.c | 2 +-
 lustre/quota/quota_master.c  | 2 +-
 17 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/lustre/ChangeLog b/lustre/ChangeLog
index 09397fe8a2..3ce0b4513c 100644
--- a/lustre/ChangeLog
+++ b/lustre/ChangeLog
@@ -54,6 +54,12 @@ Severity   : normal
 Bugzilla   : 10595
 Description: Error message improvement.
 Details    : Merging of two LCONSOLE_ERROR_MSG into one.
+
+Severity   : normal
+Bugzilla   : 12606
+Description: don't use GFP_* in generic Lustre code.
+Details    : Use cfs_alloc_* functions and CFS_* flags for code portability.
+
 --------------------------------------------------------------------------------
 
 2007-07-30         Cluster File Systems, Inc. <info@clusterfs.com>
diff --git a/lustre/include/liblustre.h b/lustre/include/liblustre.h
index 46b5fc831e..3e1963a3cc 100644
--- a/lustre/include/liblustre.h
+++ b/lustre/include/liblustre.h
@@ -413,8 +413,10 @@ static inline cfs_page_t *alloc_pages(int mask, unsigned long order)
         }
         return pg;
 }
+#define cfs_alloc_pages(mask, order)  alloc_pages((mask), (order))
 
-#define alloc_page(mask) alloc_pages((mask), 0)
+#define alloc_page(mask)      alloc_pages((mask), 0)
+#define cfs_alloc_page(mask)  alloc_page(mask)
 
 static inline void __free_pages(cfs_page_t *pg, int what)
 {
@@ -425,9 +427,11 @@ static inline void __free_pages(cfs_page_t *pg, int what)
 #endif
         free(pg);
 }
+#define __cfs_free_pages(pg, order)  __free_pages((pg), (order))
 
 #define __free_page(page) __free_pages((page), 0)
 #define free_page(page) __free_page(page)
+#define __cfs_free_page(page)  __cfs_free_pages((page), 0)
 
 static inline cfs_page_t* __grab_cache_page(unsigned long index)
 {
diff --git a/lustre/liblustre/dir.c b/lustre/liblustre/dir.c
index 50a94e2e2d..da2eb26f38 100644
--- a/lustre/liblustre/dir.c
+++ b/lustre/liblustre/dir.c
@@ -131,7 +131,7 @@ static struct page *llu_dir_read_page(struct inode *ino, unsigned long pgidx)
         int rc;
         ENTRY;
 
-        page = alloc_page(0);
+        page = cfs_alloc_page(0);
         if (!page) {
                 CERROR("alloc page failed\n");
                 RETURN(ERR_PTR(-ENOMEM));
diff --git a/lustre/llite/file.c b/lustre/llite/file.c
index 4248d35e98..19b4091d04 100644
--- a/lustre/llite/file.c
+++ b/lustre/llite/file.c
@@ -37,14 +37,14 @@ struct ll_file_data *ll_file_data_get(void)
 {
         struct ll_file_data *fd;
 
-        OBD_SLAB_ALLOC(fd, ll_file_data_slab, GFP_KERNEL, sizeof *fd);
+        OBD_SLAB_ALLOC_PTR(fd, ll_file_data_slab);
         return fd;
 }
 
 static void ll_file_data_put(struct ll_file_data *fd)
 {
         if (fd != NULL)
-                OBD_SLAB_FREE(fd, ll_file_data_slab, sizeof *fd);
+                OBD_SLAB_FREE_PTR(fd, ll_file_data_slab);
 }
 
 static int ll_close_inode_openhandle(struct inode *inode,
diff --git a/lustre/llite/lproc_llite.c b/lustre/llite/lproc_llite.c
index 8a38d08ac7..6382a4d61c 100644
--- a/lustre/llite/lproc_llite.c
+++ b/lustre/llite/lproc_llite.c
@@ -824,7 +824,7 @@ static int llite_dump_pgcache_seq_open(struct inode *inode, struct file *file)
 
         LPROCFS_ENTRY_AND_CHECK(dp);
 
-        OBD_ALLOC_GFP(dummy_llap, sizeof(*dummy_llap), GFP_KERNEL);
+        OBD_ALLOC_PTR_WAIT(dummy_llap);
         if (dummy_llap == NULL)
                 GOTO(out, rc);
 
diff --git a/lustre/llite/rw.c b/lustre/llite/rw.c
index 0fd0bf5f77..6ab6fcf9bd 100644
--- a/lustre/llite/rw.c
+++ b/lustre/llite/rw.c
@@ -591,7 +591,7 @@ static struct ll_async_page *llap_from_page(struct page *page, unsigned origin)
         if (sbi->ll_async_page_count >= sbi->ll_async_page_max)
                 llap_shrink_cache(sbi, 0);
 
-        OBD_SLAB_ALLOC(llap, ll_async_page_slab, GFP_KERNEL,
+        OBD_SLAB_ALLOC(llap, ll_async_page_slab, CFS_ALLOC_STD,
                        ll_async_page_slab_size);
         if (llap == NULL)
                 RETURN(ERR_PTR(-ENOMEM));
diff --git a/lustre/llite/rw26.c b/lustre/llite/rw26.c
index 3795de7708..c631c2bea6 100644
--- a/lustre/llite/rw26.c
+++ b/lustre/llite/rw26.c
@@ -102,7 +102,7 @@ static inline int ll_get_user_pages(int rw, unsigned long user_addr,
         page_count = ((user_addr + size + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT)-
                       (user_addr >> CFS_PAGE_SHIFT);
 
-        OBD_ALLOC_GFP(*pages, page_count * sizeof(**pages), GFP_KERNEL);
+        OBD_ALLOC_WAIT(*pages, page_count * sizeof(**pages));
         if (*pages) {
                 down_read(&current->mm->mmap_sem);
                 result = get_user_pages(current, current->mm, user_addr,
diff --git a/lustre/llite/super25.c b/lustre/llite/super25.c
index f66826c746..e9147cf5b3 100644
--- a/lustre/llite/super25.c
+++ b/lustre/llite/super25.c
@@ -41,7 +41,7 @@ static struct inode *ll_alloc_inode(struct super_block *sb)
 {
         struct ll_inode_info *lli;
         ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_ALLOC_INODE, 1);
-        OBD_SLAB_ALLOC(lli, ll_inode_cachep, GFP_KERNEL, sizeof *lli);
+        OBD_SLAB_ALLOC_PTR(lli, ll_inode_cachep);
         if (lli == NULL)
                 return NULL;
 
@@ -54,7 +54,7 @@ static struct inode *ll_alloc_inode(struct super_block *sb)
 static void ll_destroy_inode(struct inode *inode)
 {
         struct ll_inode_info *ptr = ll_i2info(inode);
-        OBD_SLAB_FREE(ptr, ll_inode_cachep, sizeof(*ptr));
+        OBD_SLAB_FREE_PTR(ptr, ll_inode_cachep);
 }
 
 int ll_init_inodecache(void)
diff --git a/lustre/lov/lov_ea.c b/lustre/lov/lov_ea.c
index 860125fd05..827533fc9e 100755
--- a/lustre/lov/lov_ea.c
+++ b/lustre/lov/lov_ea.c
@@ -95,7 +95,7 @@ struct lov_stripe_md *lsm_alloc_plain(int stripe_count, int *size)
                 return NULL;;
 
         for (i = 0; i < stripe_count; i++) {
-                OBD_SLAB_ALLOC(loi, lov_oinfo_slab, GFP_NOFS, sizeof(*loi));
+                OBD_SLAB_ALLOC(loi, lov_oinfo_slab, CFS_ALLOC_IO, sizeof(*loi));
                 if (loi == NULL)
                         goto err;
                 lsm->lsm_oinfo[i] = loi;
diff --git a/lustre/lvfs/fsfilt_ext3.c b/lustre/lvfs/fsfilt_ext3.c
index 035a355768..40c8d7b2b1 100644
--- a/lustre/lvfs/fsfilt_ext3.c
+++ b/lustre/lvfs/fsfilt_ext3.c
@@ -752,7 +752,7 @@ static int fsfilt_ext3_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
 {
         struct fsfilt_cb_data *fcb;
 
-        OBD_SLAB_ALLOC(fcb, fcb_cache, GFP_NOFS, sizeof *fcb);
+        OBD_SLAB_ALLOC(fcb, fcb_cache, CFS_ALLOC_IO, sizeof *fcb);
         if (fcb == NULL)
                 RETURN(-ENOMEM);
 
diff --git a/lustre/mds/handler.c b/lustre/mds/handler.c
index 07e565cd52..a9668220a8 100644
--- a/lustre/mds/handler.c
+++ b/lustre/mds/handler.c
@@ -97,7 +97,7 @@ static int mds_sendpage(struct ptlrpc_request *req, struct file *file,
         for (i = 0, tmpcount = count; i < npages; i++, tmpcount -= tmpsize) {
                 tmpsize = tmpcount > CFS_PAGE_SIZE ? CFS_PAGE_SIZE : tmpcount;
 
-                pages[i] = alloc_pages(GFP_KERNEL, 0);
+                pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
                 if (pages[i] == NULL)
                         GOTO(cleanup_buf, rc = -ENOMEM);
 
@@ -156,7 +156,7 @@ static int mds_sendpage(struct ptlrpc_request *req, struct file *file,
  cleanup_buf:
         for (i = 0; i < npages; i++)
                 if (pages[i])
-                        __free_pages(pages[i], 0);
+                        __cfs_free_page(pages[i]);
 
         ptlrpc_free_bulk(desc);
  out_free:
diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c
index 38ef2949d0..16e5237bb5 100644
--- a/lustre/obdclass/genops.c
+++ b/lustre/obdclass/genops.c
@@ -59,7 +59,7 @@ static struct obd_device *obd_device_alloc(void)
 {
         struct obd_device *obd;
 
-        OBD_SLAB_ALLOC(obd, obd_device_cachep, GFP_KERNEL, sizeof(*obd));
+        OBD_SLAB_ALLOC_PTR(obd, obd_device_cachep);
         if (obd != NULL) {
                 obd->obd_magic = OBD_DEVICE_MAGIC;
         }
@@ -72,7 +72,7 @@ static void obd_device_free(struct obd_device *obd)
         LASSERT(obd != NULL);
         LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC, "obd %p obd_magic %08x != %08x\n", 
                  obd, obd->obd_magic, OBD_DEVICE_MAGIC);
-        OBD_SLAB_FREE(obd, obd_device_cachep, sizeof(*obd));
+        OBD_SLAB_FREE_PTR(obd, obd_device_cachep);
 }
 EXPORT_SYMBOL(obd_device_free);
 
diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c
index ebb8caaeba..fcf1097080 100644
--- a/lustre/obdfilter/filter.c
+++ b/lustre/obdfilter/filter.c
@@ -482,7 +482,7 @@ struct filter_mod_data *filter_fmd_get(struct obd_export *exp,
         struct filter_export_data *fed = &exp->exp_filter_data;
         struct filter_mod_data *found = NULL, *fmd_new = NULL;
 
-        OBD_SLAB_ALLOC(fmd_new, ll_fmd_cachep, GFP_NOFS, sizeof(*fmd_new));
+        OBD_SLAB_ALLOC(fmd_new, ll_fmd_cachep, CFS_ALLOC_IO, sizeof(*fmd_new));
 
         spin_lock(&fed->fed_lock);
         found = filter_fmd_find_nolock(&exp->exp_obd->u.filter,fed,objid,group);
diff --git a/lustre/ost/ost_handler.c b/lustre/ost/ost_handler.c
index 512c1c6375..c56d8d003b 100644
--- a/lustre/ost/ost_handler.c
+++ b/lustre/ost/ost_handler.c
@@ -1615,7 +1615,7 @@ static void ost_thread_done(struct ptlrpc_thread *thread)
         if (tls != NULL) {
                 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
                         if (tls->page[i] != NULL)
-                                __free_page(tls->page[i]);
+                                __cfs_free_page(tls->page[i]);
                 }
                 OBD_FREE_PTR(tls);
                 thread->t_data = NULL;
@@ -1646,7 +1646,7 @@ static int ost_thread_init(struct ptlrpc_thread *thread)
                  * populate pool
                  */
                 for (i = 0; i < OST_THREAD_POOL_SIZE; ++ i) {
-                        tls->page[i] = alloc_page(OST_THREAD_POOL_GFP);
+                        tls->page[i] = cfs_alloc_page(OST_THREAD_POOL_GFP);
                         if (tls->page[i] == NULL) {
                                 ost_thread_done(thread);
                                 result = -ENOMEM;
diff --git a/lustre/ost/ost_internal.h b/lustre/ost/ost_internal.h
index 3407a96022..ecc977aec3 100644
--- a/lustre/ost/ost_internal.h
+++ b/lustre/ost/ost_internal.h
@@ -15,7 +15,7 @@ extern void ost_print_req(void *seq_file, struct ptlrpc_request *req);
  * tunables for per-thread page pool (bug 5137)
  */
 #define OST_THREAD_POOL_SIZE PTLRPC_MAX_BRW_PAGES  /* pool size in pages */
-#define OST_THREAD_POOL_GFP  GFP_HIGHUSER          /* GFP mask for pool pages */
+#define OST_THREAD_POOL_GFP  CFS_ALLOC_HIGHUSER    /* GFP mask for pool pages */
 
 struct page;
 struct niobuf_local;
diff --git a/lustre/quota/quota_context.c b/lustre/quota/quota_context.c
index 36098c7234..d2b6c2e828 100644
--- a/lustre/quota/quota_context.c
+++ b/lustre/quota/quota_context.c
@@ -290,7 +290,7 @@ static struct lustre_qunit *alloc_qunit(struct lustre_quota_ctxt *qctxt,
         struct lustre_qunit *qunit = NULL;
         ENTRY;
 
-        OBD_SLAB_ALLOC(qunit, qunit_cachep, GFP_NOFS, sizeof(*qunit));
+        OBD_SLAB_ALLOC(qunit, qunit_cachep, CFS_ALLOC_IO, sizeof(*qunit));
         if (qunit == NULL)
                 RETURN(NULL);
 
diff --git a/lustre/quota/quota_master.c b/lustre/quota/quota_master.c
index 40b359aa46..615c73cc69 100644
--- a/lustre/quota/quota_master.c
+++ b/lustre/quota/quota_master.c
@@ -112,7 +112,7 @@ static struct lustre_dquot *alloc_dquot(struct lustre_quota_info *lqi,
         struct lustre_dquot *dquot = NULL;
         ENTRY;
 
-        OBD_SLAB_ALLOC(dquot, lustre_dquot_cachep, GFP_NOFS, sizeof(*dquot));
+        OBD_SLAB_ALLOC(dquot, lustre_dquot_cachep, CFS_ALLOC_IO, sizeof(*dquot));
         if (dquot == NULL)
                 RETURN(NULL);
 
-- 
GitLab