]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/sys/alq.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / sys / alq.h
1 /*-
2  * Copyright (c) 2002, Jeffrey Roberson <jeff@freebsd.org>
3  * Copyright (c) 2008-2009, Lawrence Stewart <lstewart@freebsd.org>
4  * Copyright (c) 2010, The FreeBSD Foundation
5  * All rights reserved.
6  *
7  * Portions of this software were developed at the Centre for Advanced
8  * Internet Architectures, Swinburne University of Technology, Melbourne,
9  * Australia by Lawrence Stewart under sponsorship from the FreeBSD Foundation.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice unmodified, this list of conditions, and the following
16  *    disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * $FreeBSD$
33  *
34  */
35 #ifndef _SYS_ALQ_H_
36 #define _SYS_ALQ_H_
37
38 /*
39  * Opaque type for the Async. Logging Queue
40  */
41 struct alq;
42
43 /* The thread for the logging daemon */
44 extern struct thread *ald_thread;
45
46 /*
47  * Async. Logging Entry
48  */
49 struct ale {
50         intptr_t        ae_bytesused;   /* # bytes written to ALE. */
51         char            *ae_data;       /* Write ptr. */
52         int             ae_pad;         /* Unused, compat. */
53 };
54
55 /* Flag options. */
56 #define ALQ_NOWAIT      0x0001  /* ALQ may not sleep. */
57 #define ALQ_WAITOK      0x0002  /* ALQ may sleep. */
58 #define ALQ_NOACTIVATE  0x0004  /* Don't activate ALQ after write. */
59 #define ALQ_ORDERED     0x0010  /* Maintain write ordering between threads. */
60
61 /* Suggested mode for file creation. */
62 #define ALQ_DEFAULT_CMODE       0600
63
64 /*
65  * alq_open_flags:  Creates a new queue
66  *
67  * Arguments:
68  *      alq     Storage for a pointer to the newly created queue.
69  *      file    The filename to open for logging.
70  *      cred    Credential to authorize open and I/O with.
71  *      cmode   Creation mode for file, if new.
72  *      size    The size of the queue in bytes.
73  *      flags   ALQ_ORDERED
74  * Returns:
75  *      error from open or 0 on success
76  */
77 struct ucred;
78 int alq_open_flags(struct alq **alqp, const char *file, struct ucred *cred, int cmode,
79             int size, int flags);
80 int alq_open(struct alq **alqp, const char *file, struct ucred *cred, int cmode,
81             int size, int count);
82
83 /*
84  * alq_writen:  Write data into the queue
85  *
86  * Arguments:
87  *      alq     The queue we're writing to
88  *      data    The entry to be recorded
89  *      len     The number of bytes to write from *data
90  *      flags   (ALQ_NOWAIT || ALQ_WAITOK), ALQ_NOACTIVATE
91  *
92  * Returns:
93  *      EWOULDBLOCK if:
94  *              Waitok is ALQ_NOWAIT and the queue is full.
95  *              The system is shutting down.
96  *      0 on success.
97  */
98 int alq_writen(struct alq *alq, void *data, int len, int flags);
99 int alq_write(struct alq *alq, void *data, int flags);
100
101 /*
102  * alq_flush:  Flush the queue out to disk
103  */
104 void alq_flush(struct alq *alq);
105
106 /*
107  * alq_close:  Flush the queue and free all resources.
108  */
109 void alq_close(struct alq *alq);
110
111 /*
112  * alq_getn:  Return an entry for direct access
113  *
114  * Arguments:
115  *      alq     The queue to retrieve an entry from
116  *      len     Max number of bytes required
117  *      flags   (ALQ_NOWAIT || ALQ_WAITOK)
118  *
119  * Returns:
120  *      The next available ale on success.
121  *      NULL if:
122  *              flags is ALQ_NOWAIT and the queue is full.
123  *              The system is shutting down.
124  *
125  * This leaves the queue locked until a subsequent alq_post.
126  */
127 struct ale *alq_getn(struct alq *alq, int len, int flags);
128 struct ale *alq_get(struct alq *alq, int flags);
129
130 /*
131  * alq_post_flags:  Schedule the ale retrieved by alq_get/alq_getn for writing.
132  *      alq     The queue to post the entry to.
133  *      ale     An asynch logging entry returned by alq_get.
134  *      flags   ALQ_NOACTIVATE
135  */
136 void alq_post_flags(struct alq *alq, struct ale *ale, int flags);
137
138 static __inline void
139 alq_post(struct alq *alq, struct ale *ale)
140 {
141         alq_post_flags(alq, ale, 0);
142 }
143
144 #endif  /* _SYS_ALQ_H_ */