Sun Apr 26 22:23:02 2009 UTC ()
Provide a stateful mode for readdir/read/write.  Using them gives
a measurable boost to some fs-utils commands.


(pooka)
diff -r1.23 -r1.24 src/lib/libukfs/ukfs.c
diff -r1.7 -r1.8 src/lib/libukfs/ukfs.h

cvs diff -r1.23 -r1.24 src/lib/libukfs/ukfs.c (expand / switch to unified diff)

--- src/lib/libukfs/ukfs.c 2009/04/06 03:27:39 1.23
+++ src/lib/libukfs/ukfs.c 2009/04/26 22:23:01 1.24
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ukfs.c,v 1.23 2009/04/06 03:27:39 pooka Exp $ */ 1/* $NetBSD: ukfs.c,v 1.24 2009/04/26 22:23:01 pooka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2007, 2008 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2007, 2008 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Development of this software was supported by the 6 * Development of this software was supported by the
7 * Finnish Cultural Foundation. 7 * Finnish Cultural Foundation.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -288,84 +288,161 @@ ukfs_release(struct ukfs *fs, int flags) @@ -288,84 +288,161 @@ ukfs_release(struct ukfs *fs, int flags)
288 } 288 }
289 free(fs); 289 free(fs);
290} 290}
291 291
292#define STDCALL(ukfs, thecall) \ 292#define STDCALL(ukfs, thecall) \
293 int rv = 0; \ 293 int rv = 0; \
294 \ 294 \
295 precall(ukfs); \ 295 precall(ukfs); \
296 rv = thecall; \ 296 rv = thecall; \
297 postcall(ukfs); \ 297 postcall(ukfs); \
298 return rv; 298 return rv;
299 299
300int 300int
301ukfs_getdents(struct ukfs *ukfs, const char *dirname, off_t *off, 301ukfs_opendir(struct ukfs *ukfs, const char *dirname, struct ukfs_dircookie **c)
302 uint8_t *buf, size_t bufsize) 
303{ 302{
304 struct uio *uio; 
305 struct vnode *vp; 303 struct vnode *vp;
306 size_t resid; 304 int rv;
307 kauth_cred_t cred; 
308 int rv, eofflag; 
309 305
310 precall(ukfs); 306 precall(ukfs);
311 rv = rump_namei(RUMP_NAMEI_LOOKUP, RUMP_NAMEI_LOCKLEAF, dirname, 307 rv = rump_namei(RUMP_NAMEI_LOOKUP, RUMP_NAMEI_LOCKLEAF, dirname,
312 NULL, &vp, NULL); 308 NULL, &vp, NULL);
313 postcall(ukfs); 309 postcall(ukfs);
314 if (rv) 310
315 goto out; 311 if (rv == 0) {
316  312 RUMP_VOP_UNLOCK(vp, 0);
 313 } else {
 314 errno = rv;
 315 rv = -1;
 316 }
 317
 318 /*LINTED*/
 319 *c = (struct ukfs_dircookie *)vp;
 320 return rv;
 321}
 322
 323static int
 324getmydents(struct vnode *vp, off_t *off, uint8_t *buf, size_t bufsize)
 325{
 326 struct uio *uio;
 327 size_t resid;
 328 int rv, eofflag;
 329 kauth_cred_t cred;
 330
317 uio = rump_uio_setup(buf, bufsize, *off, RUMPUIO_READ); 331 uio = rump_uio_setup(buf, bufsize, *off, RUMPUIO_READ);
318 cred = rump_cred_suserget(); 332 cred = rump_cred_suserget();
319 rv = RUMP_VOP_READDIR(vp, uio, cred, &eofflag, NULL, NULL); 333 rv = RUMP_VOP_READDIR(vp, uio, cred, &eofflag, NULL, NULL);
320 rump_cred_suserput(cred); 334 rump_cred_suserput(cred);
321 RUMP_VOP_UNLOCK(vp, 0); 335 RUMP_VOP_UNLOCK(vp, 0);
322 *off = rump_uio_getoff(uio); 336 *off = rump_uio_getoff(uio);
323 resid = rump_uio_free(uio); 337 resid = rump_uio_free(uio);
324 rump_vp_rele(vp); 
325 338
326 out: 
327 if (rv) { 339 if (rv) {
328 errno = rv; 340 errno = rv;
329 return -1; 341 return -1;
330 } 342 }
331 343
332 /* LINTED: not totally correct return type, but follows syscall */ 344 /* LINTED: not totally correct return type, but follows syscall */
333 return bufsize - resid; 345 return bufsize - resid;
334} 346}
335 347
 348/*ARGSUSED*/
 349int
 350ukfs_getdents_cookie(struct ukfs *ukfs, struct ukfs_dircookie *c, off_t *off,
 351 uint8_t *buf, size_t bufsize)
 352{
 353 /*LINTED*/
 354 struct vnode *vp = (struct vnode *)c;
 355
 356 RUMP_VOP_LOCK(vp, RUMP_LK_SHARED);
 357 return getmydents(vp, off, buf, bufsize);
 358}
 359
 360int
 361ukfs_getdents(struct ukfs *ukfs, const char *dirname, off_t *off,
 362 uint8_t *buf, size_t bufsize)
 363{
 364 struct vnode *vp;
 365 int rv;
 366
 367 precall(ukfs);
 368 rv = rump_namei(RUMP_NAMEI_LOOKUP, RUMP_NAMEI_LOCKLEAF, dirname,
 369 NULL, &vp, NULL);
 370 postcall(ukfs);
 371 if (rv) {
 372 errno = rv;
 373 return -1;
 374 }
 375
 376 rv = getmydents(vp, off, buf, bufsize);
 377 rump_vp_rele(vp);
 378 return rv;
 379}
 380
 381/*ARGSUSED*/
 382int
 383ukfs_closedir(struct ukfs *ukfs, struct ukfs_dircookie *c)
 384{
 385
 386 /*LINTED*/
 387 rump_vp_rele((struct vnode *)c);
 388 return 0;
 389}
 390
 391int
 392ukfs_open(struct ukfs *ukfs, const char *filename, int flags)
 393{
 394 int fd;
 395
 396 precall(ukfs);
 397 fd = rump_sys_open(filename, flags, 0);
 398 postcall(ukfs);
 399 if (fd == -1)
 400 return -1;
 401
 402 return fd;
 403}
 404
336ssize_t 405ssize_t
337ukfs_read(struct ukfs *ukfs, const char *filename, off_t off, 406ukfs_read(struct ukfs *ukfs, const char *filename, off_t off,
338 uint8_t *buf, size_t bufsize) 407 uint8_t *buf, size_t bufsize)
339{ 408{
340 int fd; 409 int fd;
341 ssize_t xfer = -1; /* XXXgcc */ 410 ssize_t xfer = -1; /* XXXgcc */
342 411
343 precall(ukfs); 412 precall(ukfs);
344 fd = rump_sys_open(filename, RUMP_O_RDONLY, 0); 413 fd = rump_sys_open(filename, RUMP_O_RDONLY, 0);
345 if (fd == -1) 414 if (fd == -1)
346 goto out; 415 goto out;
347 416
348 xfer = rump_sys_pread(fd, buf, bufsize, 0, off); 417 xfer = rump_sys_pread(fd, buf, bufsize, 0, off);
349 rump_sys_close(fd); 418 rump_sys_close(fd);
350 419
351 out: 420 out:
352 postcall(ukfs); 421 postcall(ukfs);
353 if (fd == -1) { 422 if (fd == -1) {
354 return -1; 423 return -1;
355 } 424 }
356 return xfer; 425 return xfer;
357} 426}
358 427
 428/*ARGSUSED*/
 429ssize_t
 430ukfs_read_fd(struct ukfs *ukfs, int fd, off_t off, uint8_t *buf, size_t buflen)
 431{
 432
 433 return rump_sys_pread(fd, buf, buflen, 0, off);
 434}
 435
359ssize_t 436ssize_t
360ukfs_write(struct ukfs *ukfs, const char *filename, off_t off, 437ukfs_write(struct ukfs *ukfs, const char *filename, off_t off,
361 uint8_t *buf, size_t bufsize) 438 uint8_t *buf, size_t bufsize)
362{ 439{
363 int fd; 440 int fd;
364 ssize_t xfer = -1; /* XXXgcc */ 441 ssize_t xfer = -1; /* XXXgcc */
365 442
366 precall(ukfs); 443 precall(ukfs);
367 fd = rump_sys_open(filename, RUMP_O_WRONLY, 0); 444 fd = rump_sys_open(filename, RUMP_O_WRONLY, 0);
368 if (fd == -1) 445 if (fd == -1)
369 goto out; 446 goto out;
370 447
371 /* write and commit */ 448 /* write and commit */
@@ -373,26 +450,49 @@ ukfs_write(struct ukfs *ukfs, const char @@ -373,26 +450,49 @@ ukfs_write(struct ukfs *ukfs, const char
373 if (xfer > 0) 450 if (xfer > 0)
374 rump_sys_fsync(fd); 451 rump_sys_fsync(fd);
375 452
376 rump_sys_close(fd); 453 rump_sys_close(fd);
377 454
378 out: 455 out:
379 postcall(ukfs); 456 postcall(ukfs);
380 if (fd == -1) { 457 if (fd == -1) {
381 return -1; 458 return -1;
382 } 459 }
383 return xfer; 460 return xfer;
384} 461}
385 462
 463/*ARGSUSED*/
 464ssize_t
 465ukfs_write_fd(struct ukfs *ukfs, int fd, off_t off, uint8_t *buf, size_t buflen,
 466 int dosync)
 467{
 468 ssize_t xfer;
 469
 470 xfer = rump_sys_pwrite(fd, buf, buflen, 0, off);
 471 if (xfer > 0 && dosync)
 472 rump_sys_fsync(fd);
 473
 474 return xfer;
 475}
 476
 477/*ARGSUSED*/
 478int
 479ukfs_close(struct ukfs *ukfs, int fd)
 480{
 481
 482 rump_sys_close(fd);
 483 return 0;
 484}
 485
386int 486int
387ukfs_create(struct ukfs *ukfs, const char *filename, mode_t mode) 487ukfs_create(struct ukfs *ukfs, const char *filename, mode_t mode)
388{ 488{
389 int fd; 489 int fd;
390 490
391 precall(ukfs); 491 precall(ukfs);
392 fd = rump_sys_open(filename, RUMP_O_WRONLY | RUMP_O_CREAT, mode); 492 fd = rump_sys_open(filename, RUMP_O_WRONLY | RUMP_O_CREAT, mode);
393 if (fd == -1) 493 if (fd == -1)
394 return -1; 494 return -1;
395 rump_sys_close(fd); 495 rump_sys_close(fd);
396 496
397 postcall(ukfs); 497 postcall(ukfs);
398 return 0; 498 return 0;

cvs diff -r1.7 -r1.8 src/lib/libukfs/ukfs.h (expand / switch to unified diff)

--- src/lib/libukfs/ukfs.h 2008/10/07 23:16:59 1.7
+++ src/lib/libukfs/ukfs.h 2009/04/26 22:23:01 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ukfs.h,v 1.7 2008/10/07 23:16:59 pooka Exp $ */ 1/* $NetBSD: ukfs.h,v 1.8 2009/04/26 22:23:01 pooka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2007, 2008 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2007, 2008 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Development of this software was supported by the 6 * Development of this software was supported by the
7 * Finnish Cultural Foundation. 7 * Finnish Cultural Foundation.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -31,47 +31,59 @@ @@ -31,47 +31,59 @@
31#ifndef _RUMP_UKFS_H_ 31#ifndef _RUMP_UKFS_H_
32#define _RUMP_UKFS_H_ 32#define _RUMP_UKFS_H_
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35 35
36#include <stdint.h> 36#include <stdint.h>
37 37
38/* don't include NetBSD <sys/header.h> for portability */ 38/* don't include NetBSD <sys/header.h> for portability */
39struct vnode; 39struct vnode;
40struct stat; 40struct stat;
41struct timeval; 41struct timeval;
42 42
43struct ukfs; 43struct ukfs;
 44struct ukfs_dircookie;
44 45
45#define UKFS_DEFAULTMP "/" 46#define UKFS_DEFAULTMP "/"
46 47
47#define UKFS_RELFLAG_NOUNMOUNT 0x01 48#define UKFS_RELFLAG_NOUNMOUNT 0x01
48 49
49#define UKFS_VERSION 001 /* sector 001 */ 50#define UKFS_VERSION 001 /* sector 001 */
50#define ukfs_init() _ukfs_init(UKFS_VERSION) 51#define ukfs_init() _ukfs_init(UKFS_VERSION)
51 52
52__BEGIN_DECLS 53__BEGIN_DECLS
53 54
54int _ukfs_init(int); 55int _ukfs_init(int);
55struct ukfs *ukfs_mount(const char *, const char *, const char *, 56struct ukfs *ukfs_mount(const char *, const char *, const char *,
56 int, void *, size_t); 57 int, void *, size_t);
57void ukfs_release(struct ukfs *, int); 58void ukfs_release(struct ukfs *, int);
58 59
 60int ukfs_opendir(struct ukfs *, const char *,
 61 struct ukfs_dircookie **);
59int ukfs_getdents(struct ukfs *, const char *, off_t *, 62int ukfs_getdents(struct ukfs *, const char *, off_t *,
60 uint8_t *, size_t); 63 uint8_t *, size_t);
 64int ukfs_getdents_cookie(struct ukfs *, struct ukfs_dircookie *,
 65 off_t *, uint8_t *, size_t);
 66int ukfs_closedir(struct ukfs *, struct ukfs_dircookie *);
 67
 68int ukfs_open(struct ukfs *, const char *, int);
61ssize_t ukfs_read(struct ukfs *, const char *, off_t, 69ssize_t ukfs_read(struct ukfs *, const char *, off_t,
62 uint8_t *, size_t); 70 uint8_t *, size_t);
 71ssize_t ukfs_read_fd(struct ukfs *, int, off_t, uint8_t *, size_t);
63ssize_t ukfs_write(struct ukfs *, const char *, off_t, 72ssize_t ukfs_write(struct ukfs *, const char *, off_t,
64 uint8_t *, size_t); 73 uint8_t *, size_t);
 74ssize_t ukfs_write_fd(struct ukfs *, int, off_t, uint8_t *, size_t,int);
 75int ukfs_close(struct ukfs *, int);
 76
65ssize_t ukfs_readlink(struct ukfs *, const char *, char *, size_t); 77ssize_t ukfs_readlink(struct ukfs *, const char *, char *, size_t);
66 78
67int ukfs_create(struct ukfs *, const char *, mode_t); 79int ukfs_create(struct ukfs *, const char *, mode_t);
68int ukfs_mkdir(struct ukfs *, const char *, mode_t); 80int ukfs_mkdir(struct ukfs *, const char *, mode_t);
69int ukfs_mknod(struct ukfs *, const char *, mode_t, dev_t); 81int ukfs_mknod(struct ukfs *, const char *, mode_t, dev_t);
70int ukfs_mkfifo(struct ukfs *, const char *, mode_t); 82int ukfs_mkfifo(struct ukfs *, const char *, mode_t);
71int ukfs_symlink(struct ukfs *, const char *, const char *); 83int ukfs_symlink(struct ukfs *, const char *, const char *);
72 84
73int ukfs_remove(struct ukfs *, const char *); 85int ukfs_remove(struct ukfs *, const char *);
74int ukfs_rmdir(struct ukfs *, const char *); 86int ukfs_rmdir(struct ukfs *, const char *);
75 87
76int ukfs_link(struct ukfs *, const char *, const char *); 88int ukfs_link(struct ukfs *, const char *, const char *);
77int ukfs_rename(struct ukfs *, const char *, const char *); 89int ukfs_rename(struct ukfs *, const char *, const char *);