xref: /dflybsd-src/sys/vfs/hammer/hammer_signal.c (revision 2d7e662fe7a645599757bf93ef1b46168f9202e7)
1855942b6SMatthew Dillon /*
2855942b6SMatthew Dillon  * Copyright (c) 2008 The DragonFly Project.  All rights reserved.
3855942b6SMatthew Dillon  *
4855942b6SMatthew Dillon  * This code is derived from software contributed to The DragonFly Project
5855942b6SMatthew Dillon  * by Matthew Dillon <dillon@backplane.com>
6855942b6SMatthew Dillon  *
7855942b6SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
8855942b6SMatthew Dillon  * modification, are permitted provided that the following conditions
9855942b6SMatthew Dillon  * are met:
10855942b6SMatthew Dillon  *
11855942b6SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
12855942b6SMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
13855942b6SMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
14855942b6SMatthew Dillon  *    notice, this list of conditions and the following disclaimer in
15855942b6SMatthew Dillon  *    the documentation and/or other materials provided with the
16855942b6SMatthew Dillon  *    distribution.
17855942b6SMatthew Dillon  * 3. Neither the name of The DragonFly Project nor the names of its
18855942b6SMatthew Dillon  *    contributors may be used to endorse or promote products derived
19855942b6SMatthew Dillon  *    from this software without specific, prior written permission.
20855942b6SMatthew Dillon  *
21855942b6SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22855942b6SMatthew Dillon  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23855942b6SMatthew Dillon  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24855942b6SMatthew Dillon  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25855942b6SMatthew Dillon  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26855942b6SMatthew Dillon  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27855942b6SMatthew Dillon  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28855942b6SMatthew Dillon  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29855942b6SMatthew Dillon  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30855942b6SMatthew Dillon  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31855942b6SMatthew Dillon  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32855942b6SMatthew Dillon  * SUCH DAMAGE.
33855942b6SMatthew Dillon  *
34855942b6SMatthew Dillon  * $DragonFly: src/sys/vfs/hammer/hammer_signal.c,v 1.1 2008/03/20 06:08:40 dillon Exp $
35855942b6SMatthew Dillon  */
36855942b6SMatthew Dillon /*
37855942b6SMatthew Dillon  * Check for interruption when doing a long ioctl operation.
38855942b6SMatthew Dillon  */
39855942b6SMatthew Dillon 
40cbf26eb2STomohiro Kusumi #include <sys/signal2.h>
41cbf26eb2STomohiro Kusumi 
42855942b6SMatthew Dillon #include "hammer.h"
43855942b6SMatthew Dillon 
44b0aab9b9SMatthew Dillon /*
45*2d7e662fSMatthew Dillon  * Check for a user signal interrupting a long operation.  Do not allow
46*2d7e662fSMatthew Dillon  * stopping or blocking, just check to see if an actionable signal is
47*2d7e662fSMatthew Dillon  * pending.
48b0aab9b9SMatthew Dillon  */
49855942b6SMatthew Dillon int
hammer_signal_check(hammer_mount_t hmp)50855942b6SMatthew Dillon hammer_signal_check(hammer_mount_t hmp)
51855942b6SMatthew Dillon {
52855942b6SMatthew Dillon 	int sig;
53855942b6SMatthew Dillon 
543824f392SMatthew Dillon 	lwkt_user_yield();
55855942b6SMatthew Dillon 	if (++hmp->check_interrupt < 100)
56855942b6SMatthew Dillon 		return(0);
57855942b6SMatthew Dillon 	hmp->check_interrupt = 0;
58855942b6SMatthew Dillon 
59*2d7e662fSMatthew Dillon 	if ((sig = CURSIG_NOBLOCK(curthread->td_lwp)) != 0)
60855942b6SMatthew Dillon 		return(EINTR);
61855942b6SMatthew Dillon 	return(0);
62855942b6SMatthew Dillon }
63855942b6SMatthew Dillon 
64