Deleted Added
full compact
nandsim_swap.c (235537) nandsim_swap.c (241896)
1/*-
2 * Copyright (C) 2009-2012 Semihalf
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (C) 2009-2012 Semihalf
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/nand/nandsim_swap.c 235537 2012-05-17 10:11:18Z gber $");
28__FBSDID("$FreeBSD: head/sys/dev/nand/nandsim_swap.c 241896 2012-10-22 17:50:54Z kib $");
29
30#include <sys/param.h>
31#include <sys/types.h>
32#include <sys/systm.h>
33#include <sys/malloc.h>
34#include <sys/queue.h>
35#include <sys/fcntl.h>
36#include <sys/proc.h>

--- 100 unchanged lines hidden (view full) ---

137 blk_space = STAILQ_FIRST(&swap->used_bs);
138 }
139}
140
141static int
142swap_file_open(struct chip_swap *swap, const char *swap_file)
143{
144 struct nameidata nd;
29
30#include <sys/param.h>
31#include <sys/types.h>
32#include <sys/systm.h>
33#include <sys/malloc.h>
34#include <sys/queue.h>
35#include <sys/fcntl.h>
36#include <sys/proc.h>

--- 100 unchanged lines hidden (view full) ---

137 blk_space = STAILQ_FIRST(&swap->used_bs);
138 }
139}
140
141static int
142swap_file_open(struct chip_swap *swap, const char *swap_file)
143{
144 struct nameidata nd;
145 int vfslocked, flags, error;
145 int flags, error;
146
146
147 NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, swap_file,
147 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, swap_file,
148 curthread);
149
150 flags = FWRITE | FREAD | O_NOFOLLOW | O_CREAT | O_TRUNC;
151
152 error = vn_open(&nd, &flags, CHIP_SWAP_CMODE, NULL);
153 if (error) {
154 nand_debug(NDBG_SIM,"Cannot create swap file %s", swap_file);
155 NDFREE(&nd, NDF_ONLY_PNBUF);
156 return (error);
157 }
158
159 swap->swap_cred = crhold(curthread->td_ucred);
148 curthread);
149
150 flags = FWRITE | FREAD | O_NOFOLLOW | O_CREAT | O_TRUNC;
151
152 error = vn_open(&nd, &flags, CHIP_SWAP_CMODE, NULL);
153 if (error) {
154 nand_debug(NDBG_SIM,"Cannot create swap file %s", swap_file);
155 NDFREE(&nd, NDF_ONLY_PNBUF);
156 return (error);
157 }
158
159 swap->swap_cred = crhold(curthread->td_ucred);
160 vfslocked = NDHASGIANT(&nd);
161 NDFREE(&nd, NDF_ONLY_PNBUF);
162
163 /* We just unlock so we hold a reference */
164 VOP_UNLOCK(nd.ni_vp, 0);
160 NDFREE(&nd, NDF_ONLY_PNBUF);
161
162 /* We just unlock so we hold a reference */
163 VOP_UNLOCK(nd.ni_vp, 0);
165 VFS_UNLOCK_GIANT(vfslocked);
166
167 swap->swap_vp = nd.ni_vp;
168
169 return (0);
170}
171
172static void
173swap_file_close(struct chip_swap *swap)

--- 13 unchanged lines hidden (view full) ---

187swap_file_write(struct chip_swap *swap, struct block_state *blk_state)
188{
189 struct block_space *blk_space;
190 struct thread *td;
191 struct mount *mp;
192 struct vnode *vp;
193 struct uio auio;
194 struct iovec aiov;
164
165 swap->swap_vp = nd.ni_vp;
166
167 return (0);
168}
169
170static void
171swap_file_close(struct chip_swap *swap)

--- 13 unchanged lines hidden (view full) ---

185swap_file_write(struct chip_swap *swap, struct block_state *blk_state)
186{
187 struct block_space *blk_space;
188 struct thread *td;
189 struct mount *mp;
190 struct vnode *vp;
191 struct uio auio;
192 struct iovec aiov;
195 int vfslocked;
196
197 if (swap == NULL || blk_state == NULL)
198 return (-1);
199
200 blk_space = blk_state->blk_sp;
201 if (blk_state->offset == -1) {
202 blk_state->offset = swap->swap_offset;
203 swap->swap_offset += swap->blk_size;

--- 13 unchanged lines hidden (view full) ---

217 auio.uio_iov = &aiov;
218 auio.uio_offset = blk_state->offset;
219 auio.uio_segflg = UIO_SYSSPACE;
220 auio.uio_rw = UIO_WRITE;
221 auio.uio_iovcnt = 1;
222 auio.uio_resid = swap->blk_size;
223 auio.uio_td = td;
224
193
194 if (swap == NULL || blk_state == NULL)
195 return (-1);
196
197 blk_space = blk_state->blk_sp;
198 if (blk_state->offset == -1) {
199 blk_state->offset = swap->swap_offset;
200 swap->swap_offset += swap->blk_size;

--- 13 unchanged lines hidden (view full) ---

214 auio.uio_iov = &aiov;
215 auio.uio_offset = blk_state->offset;
216 auio.uio_segflg = UIO_SYSSPACE;
217 auio.uio_rw = UIO_WRITE;
218 auio.uio_iovcnt = 1;
219 auio.uio_resid = swap->blk_size;
220 auio.uio_td = td;
221
225 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
226 vn_start_write(vp, &mp, V_WAIT);
227 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
228 VOP_WRITE(vp, &auio, IO_UNIT, swap->swap_cred);
229 VOP_UNLOCK(vp, 0);
230 vn_finished_write(mp);
222 vn_start_write(vp, &mp, V_WAIT);
223 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
224 VOP_WRITE(vp, &auio, IO_UNIT, swap->swap_cred);
225 VOP_UNLOCK(vp, 0);
226 vn_finished_write(mp);
231 VFS_UNLOCK_GIANT(vfslocked);
232
233 return (0);
234}
235
236static int
237swap_file_read(struct chip_swap *swap, struct block_state *blk_state)
238{
239 struct block_space *blk_space;
240 struct thread *td;
241 struct vnode *vp;
242 struct uio auio;
243 struct iovec aiov;
227
228 return (0);
229}
230
231static int
232swap_file_read(struct chip_swap *swap, struct block_state *blk_state)
233{
234 struct block_space *blk_space;
235 struct thread *td;
236 struct vnode *vp;
237 struct uio auio;
238 struct iovec aiov;
244 int vfslocked;
245
246 if (swap == NULL || blk_state == NULL)
247 return (-1);
248
249 blk_space = blk_state->blk_sp;
250
251 nand_debug(NDBG_SIM,"restore %p[%p] at %x\n",
252 blk_space, blk_space->blk_ptr, blk_state->offset);

--- 9 unchanged lines hidden (view full) ---

262 auio.uio_iov = &aiov;
263 auio.uio_offset = blk_state->offset;
264 auio.uio_segflg = UIO_SYSSPACE;
265 auio.uio_rw = UIO_READ;
266 auio.uio_iovcnt = 1;
267 auio.uio_resid = swap->blk_size;
268 auio.uio_td = td;
269
239
240 if (swap == NULL || blk_state == NULL)
241 return (-1);
242
243 blk_space = blk_state->blk_sp;
244
245 nand_debug(NDBG_SIM,"restore %p[%p] at %x\n",
246 blk_space, blk_space->blk_ptr, blk_state->offset);

--- 9 unchanged lines hidden (view full) ---

256 auio.uio_iov = &aiov;
257 auio.uio_offset = blk_state->offset;
258 auio.uio_segflg = UIO_SYSSPACE;
259 auio.uio_rw = UIO_READ;
260 auio.uio_iovcnt = 1;
261 auio.uio_resid = swap->blk_size;
262 auio.uio_td = td;
263
270 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
271 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
272 VOP_READ(vp, &auio, 0, swap->swap_cred);
273 VOP_UNLOCK(vp, 0);
264 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
265 VOP_READ(vp, &auio, 0, swap->swap_cred);
266 VOP_UNLOCK(vp, 0);
274 VFS_UNLOCK_GIANT(vfslocked);
275
276 return (0);
277}
278
279struct chip_swap *
280nandsim_swap_init(const char *swap_file, uint32_t nof_blks, uint32_t blk_size)
281{
282 struct chip_swap *swap;

--- 107 unchanged lines hidden ---
267
268 return (0);
269}
270
271struct chip_swap *
272nandsim_swap_init(const char *swap_file, uint32_t nof_blks, uint32_t blk_size)
273{
274 struct chip_swap *swap;

--- 107 unchanged lines hidden ---