Commit 84e07b9d authored by NeilBrown's avatar NeilBrown Committed by Greg Kroah-Hartman

staging: lustre: improve API and implementation of blocking signals.

According to comment for set_current_blocked() in
kernel/signal.c, changing ->blocked directly is wrong.
sigprocmask() should be called instead.

So change cfs_block_sigsinv() and cfs_restore_sigs()
to use sigprocmask().
For consistency, change them to pass the sigset_t by reference
rather than by value.

Also fix cfs_block_sigsinv() so that it correctly blocks
signals above 32 on a 32bit host.
Signed-off-by: default avatarNeilBrown <neilb@suse.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 99c1ffc9
...@@ -67,8 +67,8 @@ ...@@ -67,8 +67,8 @@
/* /*
* Defined by platform * Defined by platform
*/ */
sigset_t cfs_block_sigsinv(unsigned long sigs); void cfs_block_sigsinv(unsigned long sigs, sigset_t *sigset);
void cfs_restore_sigs(sigset_t sigset); void cfs_restore_sigs(sigset_t *sigset);
struct libcfs_ioctl_handler { struct libcfs_ioctl_handler {
struct list_head item; struct list_head item;
......
...@@ -44,29 +44,19 @@ ...@@ -44,29 +44,19 @@
#endif #endif
/* Block all signals except for the @sigs */ /* Block all signals except for the @sigs */
sigset_t cfs_block_sigsinv(unsigned long sigs) void cfs_block_sigsinv(unsigned long sigs, sigset_t *old)
{ {
unsigned long flags; sigset_t new;
sigset_t old;
spin_lock_irqsave(&current->sighand->siglock, flags); siginitsetinv(&new, sigs);
old = current->blocked; sigorsets(&new, &current->blocked, &new);
sigaddsetmask(&current->blocked, ~sigs); sigprocmask(SIG_BLOCK, &new, old);
recalc_sigpending();
spin_unlock_irqrestore(&current->sighand->siglock, flags);
return old;
} }
EXPORT_SYMBOL(cfs_block_sigsinv); EXPORT_SYMBOL(cfs_block_sigsinv);
void void
cfs_restore_sigs(sigset_t old) cfs_restore_sigs(sigset_t *old)
{ {
unsigned long flags; sigprocmask(SIG_SETMASK, old, NULL);
spin_lock_irqsave(&current->sighand->siglock, flags);
current->blocked = old;
recalc_sigpending();
spin_unlock_irqrestore(&current->sighand->siglock, flags);
} }
EXPORT_SYMBOL(cfs_restore_sigs); EXPORT_SYMBOL(cfs_restore_sigs);
...@@ -94,31 +94,31 @@ static inline int l_fatal_signal_pending(struct task_struct *p) ...@@ -94,31 +94,31 @@ static inline int l_fatal_signal_pending(struct task_struct *p)
*/ */
#define l_wait_event_abortable(wq, condition) \ #define l_wait_event_abortable(wq, condition) \
({ \ ({ \
sigset_t __blocked; \ sigset_t __old_blocked; \
int __ret = 0; \ int __ret = 0; \
__blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS); \ cfs_block_sigsinv(LUSTRE_FATAL_SIGS, &__old_blocked); \
__ret = wait_event_interruptible(wq, condition); \ __ret = wait_event_interruptible(wq, condition); \
cfs_restore_sigs(__blocked); \ cfs_restore_sigs(&__old_blocked); \
__ret; \ __ret; \
}) })
#define l_wait_event_abortable_timeout(wq, condition, timeout) \ #define l_wait_event_abortable_timeout(wq, condition, timeout) \
({ \ ({ \
sigset_t __blocked; \ sigset_t __old_blocked; \
int __ret = 0; \ int __ret = 0; \
__blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS); \ cfs_block_sigsinv(LUSTRE_FATAL_SIGS, &__old_blocked); \
__ret = wait_event_interruptible_timeout(wq, condition, timeout);\ __ret = wait_event_interruptible_timeout(wq, condition, timeout);\
cfs_restore_sigs(__blocked); \ cfs_restore_sigs(&__old_blocked); \
__ret; \ __ret; \
}) })
#define l_wait_event_abortable_exclusive(wq, condition) \ #define l_wait_event_abortable_exclusive(wq, condition) \
({ \ ({ \
sigset_t __blocked; \ sigset_t __old_blocked; \
int __ret = 0; \ int __ret = 0; \
__blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS); \ cfs_block_sigsinv(LUSTRE_FATAL_SIGS, &__old_blocked); \
__ret = wait_event_interruptible_exclusive(wq, condition); \ __ret = wait_event_interruptible_exclusive(wq, condition); \
cfs_restore_sigs(__blocked); \ cfs_restore_sigs(&__old_blocked); \
__ret; \ __ret; \
}) })
#endif /* _LUSTRE_LIB_H */ #endif /* _LUSTRE_LIB_H */
...@@ -177,14 +177,14 @@ static int ll_page_mkwrite0(struct vm_area_struct *vma, struct page *vmpage, ...@@ -177,14 +177,14 @@ static int ll_page_mkwrite0(struct vm_area_struct *vma, struct page *vmpage,
vio->u.fault.ft_vma = vma; vio->u.fault.ft_vma = vma;
vio->u.fault.ft_vmpage = vmpage; vio->u.fault.ft_vmpage = vmpage;
set = cfs_block_sigsinv(sigmask(SIGKILL) | sigmask(SIGTERM)); cfs_block_sigsinv(sigmask(SIGKILL) | sigmask(SIGTERM), &set);
inode = vvp_object_inode(io->ci_obj); inode = vvp_object_inode(io->ci_obj);
lli = ll_i2info(inode); lli = ll_i2info(inode);
result = cl_io_loop(env, io); result = cl_io_loop(env, io);
cfs_restore_sigs(set); cfs_restore_sigs(&set);
if (result == 0) { if (result == 0) {
struct inode *inode = file_inode(vma->vm_file); struct inode *inode = file_inode(vma->vm_file);
...@@ -334,7 +334,7 @@ static int ll_fault(struct vm_fault *vmf) ...@@ -334,7 +334,7 @@ static int ll_fault(struct vm_fault *vmf)
* so that it can be killed by admin but not cause segfault by * so that it can be killed by admin but not cause segfault by
* other signals. * other signals.
*/ */
set = cfs_block_sigsinv(sigmask(SIGKILL) | sigmask(SIGTERM)); cfs_block_sigsinv(sigmask(SIGKILL) | sigmask(SIGTERM), &set);
restart: restart:
result = ll_fault0(vmf->vma, vmf); result = ll_fault0(vmf->vma, vmf);
...@@ -360,7 +360,7 @@ static int ll_fault(struct vm_fault *vmf) ...@@ -360,7 +360,7 @@ static int ll_fault(struct vm_fault *vmf)
result = VM_FAULT_LOCKED; result = VM_FAULT_LOCKED;
} }
cfs_restore_sigs(set); cfs_restore_sigs(&set);
return result; return result;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment