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