[PATCH 01/19] Promote current_{set, restore}_flags_nested from xfs to global.

2014-04-15 Thread NeilBrown
These are useful macros from xfs for modifying current->flags.
Other places in the kernel perform the same task in various different
ways.
This patch moves the macros from xfs to include/linux/sched.h and
changes all code which temporarily sets a current->flags flag to
use these macros.

This does not change functionality in any important, but does fix a
few sites which assume that PF_FSTRANS is not already set and so
arbitrarily set and then clear it.  The new code is more careful and
will only clear it if it was previously clear.

Signed-off-by: NeilBrown 
---
 drivers/base/power/runtime.c|6 +++---
 drivers/block/nbd.c |6 +++---
 drivers/md/dm-bufio.c   |6 +++---
 drivers/md/dm-ioctl.c   |6 +++---
 drivers/mtd/nand/nandsim.c  |   28 
 drivers/scsi/iscsi_tcp.c|6 +++---
 drivers/usb/core/hub.c  |6 +++---
 fs/fs-writeback.c   |5 +++--
 fs/xfs/xfs_linux.h  |7 ---
 include/linux/sched.h   |   27 ---
 kernel/softirq.c|6 +++---
 mm/migrate.c|9 -
 mm/page_alloc.c |   10 ++
 mm/vmscan.c |   10 ++
 net/core/dev.c  |6 +++---
 net/core/sock.c |6 +++---
 net/sunrpc/sched.c  |5 +++--
 net/sunrpc/xprtrdma/transport.c |5 +++--
 net/sunrpc/xprtsock.c   |   17 ++---
 19 files changed, 78 insertions(+), 99 deletions(-)

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 72e00e66ecc5..02448f11c879 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -348,7 +348,7 @@ static int rpm_callback(int (*cb)(struct device *), struct 
device *dev)
return -ENOSYS;
 
if (dev->power.memalloc_noio) {
-   unsigned int noio_flag;
+   unsigned int pflags;
 
/*
 * Deadlock might be caused if memory allocation with
@@ -359,9 +359,9 @@ static int rpm_callback(int (*cb)(struct device *), struct 
device *dev)
 * device, so network device and its ancestor should
 * be marked as memalloc_noio too.
 */
-   noio_flag = memalloc_noio_save();
+   current_set_flags_nested(, PF_MEMALLOC_NOIO);
retval = __rpm_callback(cb, dev);
-   memalloc_noio_restore(noio_flag);
+   current_restore_flags_nested(, PF_MEMALLOC_NOIO);
} else {
retval = __rpm_callback(cb, dev);
}
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 55298db36b2d..d3ddfa8a4da4 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -158,7 +158,7 @@ static int sock_xmit(struct nbd_device *nbd, int send, void 
*buf, int size,
struct msghdr msg;
struct kvec iov;
sigset_t blocked, oldset;
-   unsigned long pflags = current->flags;
+   unsigned int pflags;
 
if (unlikely(!sock)) {
dev_err(disk_to_dev(nbd->disk),
@@ -172,7 +172,7 @@ static int sock_xmit(struct nbd_device *nbd, int send, void 
*buf, int size,
siginitsetinv(, sigmask(SIGKILL));
sigprocmask(SIG_SETMASK, , );
 
-   current->flags |= PF_MEMALLOC;
+   current_set_flags_nested(, PF_MEMALLOC);
do {
sock->sk->sk_allocation = GFP_NOIO | __GFP_MEMALLOC;
iov.iov_base = buf;
@@ -220,7 +220,7 @@ static int sock_xmit(struct nbd_device *nbd, int send, void 
*buf, int size,
} while (size > 0);
 
sigprocmask(SIG_SETMASK, , NULL);
-   tsk_restore_flags(current, pflags, PF_MEMALLOC);
+   current_restore_flags_nested(, PF_MEMALLOC);
 
return result;
 }
diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index 66c5d130c8c2..f5fa93ea3a59 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -322,7 +322,7 @@ static void __cache_size_refresh(void)
 static void *alloc_buffer_data(struct dm_bufio_client *c, gfp_t gfp_mask,
   enum data_mode *data_mode)
 {
-   unsigned noio_flag;
+   unsigned int pflags;
void *ptr;
 
if (c->block_size <= DM_BUFIO_BLOCK_SIZE_SLAB_LIMIT) {
@@ -350,12 +350,12 @@ static void *alloc_buffer_data(struct dm_bufio_client *c, 
gfp_t gfp_mask,
 */
 
if (gfp_mask & __GFP_NORETRY)
-   noio_flag = memalloc_noio_save();
+   current_set_flags_nested(, PF_MEMALLOC_NOIO);
 
ptr = __vmalloc(c->block_size, gfp_mask | __GFP_HIGHMEM, PAGE_KERNEL);
 
if (gfp_mask & __GFP_NORETRY)
-   memalloc_noio_restore(noio_flag);
+   current_restore_flags_nested(, PF_MEMALLOC_NOIO);
 
return ptr;
 }
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index 51521429fb59..5409533f22b5 100644
--- 

[PATCH 01/19] Promote current_{set, restore}_flags_nested from xfs to global.

2014-04-15 Thread NeilBrown
These are useful macros from xfs for modifying current-flags.
Other places in the kernel perform the same task in various different
ways.
This patch moves the macros from xfs to include/linux/sched.h and
changes all code which temporarily sets a current-flags flag to
use these macros.

This does not change functionality in any important, but does fix a
few sites which assume that PF_FSTRANS is not already set and so
arbitrarily set and then clear it.  The new code is more careful and
will only clear it if it was previously clear.

Signed-off-by: NeilBrown ne...@suse.de
---
 drivers/base/power/runtime.c|6 +++---
 drivers/block/nbd.c |6 +++---
 drivers/md/dm-bufio.c   |6 +++---
 drivers/md/dm-ioctl.c   |6 +++---
 drivers/mtd/nand/nandsim.c  |   28 
 drivers/scsi/iscsi_tcp.c|6 +++---
 drivers/usb/core/hub.c  |6 +++---
 fs/fs-writeback.c   |5 +++--
 fs/xfs/xfs_linux.h  |7 ---
 include/linux/sched.h   |   27 ---
 kernel/softirq.c|6 +++---
 mm/migrate.c|9 -
 mm/page_alloc.c |   10 ++
 mm/vmscan.c |   10 ++
 net/core/dev.c  |6 +++---
 net/core/sock.c |6 +++---
 net/sunrpc/sched.c  |5 +++--
 net/sunrpc/xprtrdma/transport.c |5 +++--
 net/sunrpc/xprtsock.c   |   17 ++---
 19 files changed, 78 insertions(+), 99 deletions(-)

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 72e00e66ecc5..02448f11c879 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -348,7 +348,7 @@ static int rpm_callback(int (*cb)(struct device *), struct 
device *dev)
return -ENOSYS;
 
if (dev-power.memalloc_noio) {
-   unsigned int noio_flag;
+   unsigned int pflags;
 
/*
 * Deadlock might be caused if memory allocation with
@@ -359,9 +359,9 @@ static int rpm_callback(int (*cb)(struct device *), struct 
device *dev)
 * device, so network device and its ancestor should
 * be marked as memalloc_noio too.
 */
-   noio_flag = memalloc_noio_save();
+   current_set_flags_nested(pflags, PF_MEMALLOC_NOIO);
retval = __rpm_callback(cb, dev);
-   memalloc_noio_restore(noio_flag);
+   current_restore_flags_nested(pflags, PF_MEMALLOC_NOIO);
} else {
retval = __rpm_callback(cb, dev);
}
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 55298db36b2d..d3ddfa8a4da4 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -158,7 +158,7 @@ static int sock_xmit(struct nbd_device *nbd, int send, void 
*buf, int size,
struct msghdr msg;
struct kvec iov;
sigset_t blocked, oldset;
-   unsigned long pflags = current-flags;
+   unsigned int pflags;
 
if (unlikely(!sock)) {
dev_err(disk_to_dev(nbd-disk),
@@ -172,7 +172,7 @@ static int sock_xmit(struct nbd_device *nbd, int send, void 
*buf, int size,
siginitsetinv(blocked, sigmask(SIGKILL));
sigprocmask(SIG_SETMASK, blocked, oldset);
 
-   current-flags |= PF_MEMALLOC;
+   current_set_flags_nested(pflags, PF_MEMALLOC);
do {
sock-sk-sk_allocation = GFP_NOIO | __GFP_MEMALLOC;
iov.iov_base = buf;
@@ -220,7 +220,7 @@ static int sock_xmit(struct nbd_device *nbd, int send, void 
*buf, int size,
} while (size  0);
 
sigprocmask(SIG_SETMASK, oldset, NULL);
-   tsk_restore_flags(current, pflags, PF_MEMALLOC);
+   current_restore_flags_nested(pflags, PF_MEMALLOC);
 
return result;
 }
diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index 66c5d130c8c2..f5fa93ea3a59 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -322,7 +322,7 @@ static void __cache_size_refresh(void)
 static void *alloc_buffer_data(struct dm_bufio_client *c, gfp_t gfp_mask,
   enum data_mode *data_mode)
 {
-   unsigned noio_flag;
+   unsigned int pflags;
void *ptr;
 
if (c-block_size = DM_BUFIO_BLOCK_SIZE_SLAB_LIMIT) {
@@ -350,12 +350,12 @@ static void *alloc_buffer_data(struct dm_bufio_client *c, 
gfp_t gfp_mask,
 */
 
if (gfp_mask  __GFP_NORETRY)
-   noio_flag = memalloc_noio_save();
+   current_set_flags_nested(pflags, PF_MEMALLOC_NOIO);
 
ptr = __vmalloc(c-block_size, gfp_mask | __GFP_HIGHMEM, PAGE_KERNEL);
 
if (gfp_mask  __GFP_NORETRY)
-   memalloc_noio_restore(noio_flag);
+   current_restore_flags_nested(pflags, PF_MEMALLOC_NOIO);
 
return ptr;
 }
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c