OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [fs/] [autofs/] [waitq.c] - Blame information for rev 1765

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/* -*- linux-c -*- --------------------------------------------------------- *
2
 *
3
 * linux/fs/autofs/waitq.c
4
 *
5
 *  Copyright 1997 Transmeta Corporation -- All Rights Reserved
6
 *
7
 * This file is part of the Linux kernel and is made available under
8
 * the terms of the GNU General Public License, version 2, or at your
9
 * option, any later version, incorporated herein by reference.
10
 *
11
 * ------------------------------------------------------------------------- */
12
 
13
#include <linux/malloc.h>
14
#include <linux/sched.h>
15
#include <linux/signal.h>
16
#include <linux/file.h>
17
#include "autofs_i.h"
18
 
19
/* We make this a static variable rather than a part of the superblock; it
20
   is better if we don't reassign numbers easily even across filesystems */
21
static int autofs_next_wait_queue = 1;
22
 
23
void autofs_catatonic_mode(struct autofs_sb_info *sbi)
24
{
25
        struct autofs_wait_queue *wq, *nwq;
26
 
27
        DPRINTK(("autofs: entering catatonic mode\n"));
28
 
29
        sbi->catatonic = 1;
30
        wq = sbi->queues;
31
        sbi->queues = NULL;     /* Erase all wait queues */
32
        while ( wq ) {
33
                nwq = wq->next;
34
                wq->status = -ENOENT; /* Magic is gone - report failure */
35
                kfree(wq->name);
36
                wq->name = NULL;
37
                wake_up(&wq->queue);
38
                wq = nwq;
39
        }
40
        fput(sbi->pipe, sbi->pipe->f_inode);    /* Close the pipe */
41
}
42
 
43
static int autofs_write(struct file *file, const void *addr, int bytes)
44
{
45
        unsigned short fs;
46
        unsigned long old_signal;
47
        const char *data = (const char *)addr;
48
        int written = 0;
49
 
50
        /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
51
 
52
        /* Save pointer to user space and point back to kernel space */
53
        fs = get_fs();
54
        set_fs(KERNEL_DS);
55
 
56
        old_signal = current->signal;
57
 
58
        while ( bytes && (written = file->f_op->write(file->f_inode,file,data,bytes)) > 0 ) {
59
                data += written;
60
                bytes -= written;
61
        }
62
 
63
        if ( written == -EPIPE && !(old_signal & (1 << (SIGPIPE-1))) ) {
64
                /* Keep the currently executing process from receiving a
65
                   SIGPIPE unless it was already supposed to get one */
66
                current->signal &= ~(1 << (SIGPIPE-1));
67
        }
68
        set_fs(fs);
69
 
70
        return (bytes > 0);
71
}
72
 
73
static void autofs_notify_daemon(struct autofs_sb_info *sbi, struct autofs_wait_queue *wq)
74
{
75
        struct autofs_packet_missing pkt;
76
 
77
        DPRINTK(("autofs_wait: wait id = 0x%08lx, name = ", wq->wait_queue_token));
78
        autofs_say(wq->name,wq->len);
79
 
80
        memset(&pkt,0,sizeof pkt); /* For security reasons */
81
 
82
        pkt.hdr.proto_version = AUTOFS_PROTO_VERSION;
83
        pkt.hdr.type = autofs_ptype_missing;
84
        pkt.wait_queue_token = wq->wait_queue_token;
85
        pkt.len = wq->len;
86
        memcpy(pkt.name, wq->name, pkt.len);
87
        pkt.name[pkt.len] = '\0';
88
 
89
        if ( autofs_write(sbi->pipe,&pkt,sizeof(struct autofs_packet_missing)) )
90
                autofs_catatonic_mode(sbi);
91
}
92
 
93
int autofs_wait(struct autofs_sb_info *sbi, autofs_hash_t hash, const char *name, int len)
94
{
95
        struct autofs_wait_queue *wq;
96
        int status;
97
 
98
        for ( wq = sbi->queues ; wq ; wq = wq->next ) {
99
                if ( wq->hash == hash &&
100
                     wq->len == len &&
101
                     wq->name && !memcmp(wq->name,name,len) )
102
                        break;
103
        }
104
 
105
        if ( !wq ) {
106
                /* Create a new wait queue */
107
                wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL);
108
                if ( !wq )
109
                        return -ENOMEM;
110
 
111
                wq->name = kmalloc(len,GFP_KERNEL);
112
                if ( !wq->name ) {
113
                        kfree(wq);
114
                        return -ENOMEM;
115
                }
116
                wq->wait_queue_token = autofs_next_wait_queue++;
117
                init_waitqueue(&wq->queue);
118
                wq->hash = hash;
119
                wq->len = len;
120
                wq->status = -EINTR; /* Status return if interrupted */
121
                memcpy(wq->name, name, len);
122
                wq->next = sbi->queues;
123
                sbi->queues = wq;
124
 
125
                /* autofs_notify_daemon() may block */
126
                wq->wait_ctr = 2;
127
                autofs_notify_daemon(sbi,wq);
128
        } else
129
                wq->wait_ctr++;
130
 
131
        if ( wq->name ) {
132
                /* wq->name is NULL if and only if the lock is released */
133
                interruptible_sleep_on(&wq->queue);
134
        } else {
135
                DPRINTK(("autofs_wait: skipped sleeping\n"));
136
        }
137
 
138
        status = wq->status;
139
 
140
        if ( ! --wq->wait_ctr ) /* Are we the last process to need status? */
141
                kfree(wq);
142
 
143
        return status;
144
}
145
 
146
 
147
int autofs_wait_release(struct autofs_sb_info *sbi, unsigned long wait_queue_token, int status)
148
{
149
        struct autofs_wait_queue *wq, **wql;
150
 
151
        for ( wql = &sbi->queues ; (wq = *wql) ; wql = &wq->next ) {
152
                if ( wq->wait_queue_token == wait_queue_token )
153
                        break;
154
        }
155
        if ( !wq )
156
                return -EINVAL;
157
 
158
        *wql = wq->next;        /* Unlink from chain */
159
        kfree(wq->name);
160
        wq->name = NULL;        /* Do not wait on this queue */
161
 
162
        wq->status = status;
163
 
164
        if ( ! --wq->wait_ctr ) /* Is anyone still waiting for this guy? */
165
                kfree(wq);
166
        else
167
                wake_up(&wq->queue);
168
 
169
        return 0;
170
}
171
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.