diff options
author | Lars Müller | 2008-03-01 19:30:38 +0100 |
---|---|---|
committer | Lars Müller | 2008-03-01 19:30:38 +0100 |
commit | 93b9103f7383d400616d222606c294e07b16e1aa (patch) | |
tree | 611a39f7bc1d1dd5a4335157ef95c101d64dddc8 /kernel/misc.c | |
download | dnbd2-93b9103f7383d400616d222606c294e07b16e1aa.tar.gz dnbd2-93b9103f7383d400616d222606c294e07b16e1aa.tar.xz dnbd2-93b9103f7383d400616d222606c294e07b16e1aa.zip |
Import dnbd* from the former openslx-contrib repo as of revision 92.
openslx-contrib is currently read only and will get removed in some
days.
git-svn-id: http://svn.openslx.org/svn/openslx/contrib/dnbd2/trunk@1592 95ad53e4-c205-0410-b2fa-d234c58c8868
Diffstat (limited to 'kernel/misc.c')
-rw-r--r-- | kernel/misc.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/kernel/misc.c b/kernel/misc.c new file mode 100644 index 0000000..2756bef --- /dev/null +++ b/kernel/misc.c @@ -0,0 +1,84 @@ +/* + * kernel/misc.c + */ + + +#include "dnbd2.h" +#include "misc.h" + + +uint16_t diff(uint16_t then) +{ + int diff = jiffies & 0xffff; + diff -= then; + if (diff < 0) + diff += 1 << 16; + return diff; +} + + +int sock_xmit(struct socket *sock, int send, void *buf, int size) +{ + int result; + struct msghdr msg; + struct kvec iov; + unsigned long flags; + sigset_t oldset; + + spin_lock_irqsave(¤t->sighand->siglock, flags); + oldset = current->blocked; + sigfillset(¤t->blocked); + sigdelsetmask(¤t->blocked, sigmask(SIGKILL)); + recalc_sigpending(); + spin_unlock_irqrestore(¤t->sighand->siglock, flags); + + do { + sock->sk->sk_allocation = GFP_NOIO; + iov.iov_base = buf; + iov.iov_len = size; + msg.msg_name = NULL; + msg.msg_namelen = 0; + msg.msg_control = NULL; + msg.msg_controllen = 0; + msg.msg_flags = MSG_NOSIGNAL; + + if (send) + result = kernel_sendmsg(sock, &msg, &iov, 1, size); + else + result = kernel_recvmsg(sock, &msg, &iov, 1, size, 0); + + if (signal_pending(current)) { + siginfo_t info; + spin_lock_irqsave(¤t->sighand->siglock, flags); + dequeue_signal(current, ¤t->blocked, &info); + spin_unlock_irqrestore(¤t->sighand->siglock, + flags); + result = -EINTR; + break; + } + + if (result <= 0) { + if (result == 0) + result = -EPIPE; + break; + } + size -= result; + buf += result; + } while (size > 0); + + spin_lock_irqsave(¤t->sighand->siglock, flags); + current->blocked = oldset; + recalc_sigpending(); + spin_unlock_irqrestore(¤t->sighand->siglock, flags); + + return result; +} + + +char *inet_ntoa(uint32_t ip) +{ + static char buf[sizeof "aaa.bbb.ccc.ddd"]; + unsigned char *nums = (unsigned char *)&ip; + sprintf(buf, "%u.%u.%u.%u", nums[0], nums[1], nums[2], nums[3]); + return buf; +} |