From owner-svn-src-projects@FreeBSD.ORG Sat Apr 7 05:32:06 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DA218106564A; Sat, 7 Apr 2012 05:32:06 +0000 (UTC) (envelope-from gber@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C45EA8FC18; Sat, 7 Apr 2012 05:32:06 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q375W6w5044785; Sat, 7 Apr 2012 05:32:06 GMT (envelope-from gber@svn.freebsd.org) Received: (from gber@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q375W68c044780; Sat, 7 Apr 2012 05:32:06 GMT (envelope-from gber@svn.freebsd.org) Message-Id: <201204070532.q375W68c044780@svn.freebsd.org> From: Grzegorz Bernacki Date: Sat, 7 Apr 2012 05:32:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r233984 - in projects/nand: lib/libnandfs sbin/nandfs X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Apr 2012 05:32:06 -0000 Author: gber Date: Sat Apr 7 05:32:06 2012 New Revision: 233984 URL: http://svn.freebsd.org/changeset/base/233984 Log: nandfs: remove locks from libnandfs and tools accordingly Obtained from: Semihalf Supported by: FreeBSD Foundation, Juniper Networks Modified: projects/nand/lib/libnandfs/libnandfs.h projects/nand/lib/libnandfs/nandfs.c projects/nand/sbin/nandfs/mksnap.c projects/nand/sbin/nandfs/rmsnap.c Modified: projects/nand/lib/libnandfs/libnandfs.h ============================================================================== --- projects/nand/lib/libnandfs/libnandfs.h Sat Apr 7 05:25:13 2012 (r233983) +++ projects/nand/lib/libnandfs/libnandfs.h Sat Apr 7 05:32:06 2012 (r233984) @@ -46,19 +46,10 @@ const char *nandfs_errmsg(struct nandfs void nandfs_init(struct nandfs *, const char *); void nandfs_destroy(struct nandfs *); -int nandfs_cleanerd_set(struct nandfs *); -int nandfs_cleanerd_unset(struct nandfs *); - const char *nandfs_dev(struct nandfs *); int nandfs_open(struct nandfs *); -int nandfs_open_rw(struct nandfs *); -int nandfs_open_dev(struct nandfs *); void nandfs_close(struct nandfs *); -void nandfs_close_dev(struct nandfs *); - -int nandfs_lock(struct nandfs *, int write); -int nandfs_unlock(struct nandfs *); ssize_t nandfs_get_cp(struct nandfs *, uint64_t, struct nandfs_cpinfo *, size_t); Modified: projects/nand/lib/libnandfs/nandfs.c ============================================================================== --- projects/nand/lib/libnandfs/nandfs.c Sat Apr 7 05:25:13 2012 (r233983) +++ projects/nand/lib/libnandfs/nandfs.c Sat Apr 7 05:32:06 2012 (r233984) @@ -50,8 +50,6 @@ __FBSDID("$FreeBSD$"); #define NANDFS_IS_OPENED 0x2 #define NANDFS_IS_OPENED_DEV 0x4 #define NANDFS_IS_ERROR 0x8 -#define NANDFS_IS_LOCKED 0x10 -#define NANDFS_IS_READONLY 0x20 #define DEBUG #undef DEBUG @@ -66,12 +64,6 @@ __FBSDID("$FreeBSD$"); #define NANDFS_ASSERT_VALID_DEV(fs) \ assert(((fs)->n_flags & (NANDFS_IS_VALID | NANDFS_IS_OPENED_DEV)) == \ (NANDFS_IS_VALID | NANDFS_IS_OPENED_DEV)) -#define NANDFS_ASSERT_RDWR(fs) \ - assert(!((fs)->n_flags & NANDFS_IS_READONLY)) -#define NANDFS_ASSERT_LOCKED(fs) \ - assert((fs)->n_flags & NANDFS_IS_LOCKED) -#define NANDFS_ASSERT_UNLOCKED(fs) \ - assert(!((fs)->n_flags & NANDFS_IS_LOCKED)) int nandfs_iserror(struct nandfs *fs) @@ -104,88 +96,6 @@ nandfs_seterr(struct nandfs *fs, const c fs->n_flags |= NANDFS_IS_ERROR; } -int -nandfs_cleanerd_set(struct nandfs *fs) -{ - - NANDFS_ASSERT_VALID_DEV(fs); - - if (ioctl(fs->n_iocfd, NANDFS_IOCTL_CLEANERD_SET) == -1) { - nandfs_seterr(fs, "%s", strerror(errno)); - return (-1); - } - - return (0); -} - -int -nandfs_cleanerd_unset(struct nandfs *fs) -{ - - NANDFS_ASSERT_VALID_DEV(fs); - - if (ioctl(fs->n_iocfd, NANDFS_IOCTL_CLEANERD_UNSET) == -1) { - nandfs_seterr(fs, "%s", strerror(errno)); - return (-1); - } - - return (0); -} - -int -nandfs_lock(struct nandfs *fs, int rdwr) -{ - struct flock lck; - int error; - - NANDFS_ASSERT_VALID(fs); - NANDFS_ASSERT_RDWR(fs); - NANDFS_ASSERT_UNLOCKED(fs); - - lck.l_type = (rdwr ? F_WRLCK : F_RDLCK); - lck.l_start = 0; - lck.l_whence = SEEK_SET; - lck.l_len = 1; - - error = fcntl(fs->n_iocfd, F_SETLKW, &lck); - if (error == -1) { - nandfs_seterr(fs, "couldn't lock %s: %s", fs->n_ioc, - strerror(errno)); - return (-1); - } - - fs->n_flags |= NANDFS_IS_LOCKED; - - return (0); -} - -int -nandfs_unlock(struct nandfs *fs) -{ - struct flock lck; - int error; - - NANDFS_ASSERT_VALID(fs); - NANDFS_ASSERT_RDWR(fs); - NANDFS_ASSERT_LOCKED(fs); - - lck.l_type = F_UNLCK; - lck.l_start = 0; - lck.l_whence = SEEK_SET; - lck.l_len = 1; - - error = fcntl(fs->n_iocfd, F_SETLK, &lck); - if (error == -1) { - nandfs_seterr(fs, "couldn't unlock %s: %s", fs->n_ioc, - strerror(errno)); - return (-1); - } - - fs->n_flags &= ~NANDFS_IS_LOCKED; - - return (0); -} - const char * nandfs_dev(struct nandfs *fs) { @@ -209,26 +119,18 @@ nandfs_destroy(struct nandfs *fs) assert(fs->n_iocfd == -1); fs->n_flags &= - ~(NANDFS_IS_ERROR | NANDFS_IS_VALID | NANDFS_IS_READONLY); + ~(NANDFS_IS_ERROR | NANDFS_IS_VALID); assert(fs->n_flags == 0); } -static int -_nandfs_open(struct nandfs *fs, int rdwr) +int +nandfs_open(struct nandfs *fs) { struct nandfs_fsinfo fsinfo; - int flags; fs->n_flags |= NANDFS_IS_OPENED; - if (rdwr) - flags = O_RDWR; - else { - fs->n_flags |= NANDFS_IS_READONLY; - flags = O_RDONLY; - } - - fs->n_iocfd = open(fs->n_ioc, flags, S_IRUSR | S_IWUSR | S_IRGRP | + fs->n_iocfd = open(fs->n_ioc, O_RDONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (fs->n_iocfd == -1) { nandfs_seterr(fs, "couldn't open %s: %s", fs->n_ioc, @@ -249,39 +151,6 @@ _nandfs_open(struct nandfs *fs, int rdwr return (0); } -int -nandfs_open(struct nandfs *fs) -{ - - return (_nandfs_open(fs, 0)); -} - -int -nandfs_open_rw(struct nandfs *fs) -{ - - return (_nandfs_open(fs, 1)); -} - -int -nandfs_open_dev(struct nandfs *fs) -{ - - fs->n_flags |= NANDFS_IS_OPENED_DEV; - - if (nandfs_open_rw(fs) == -1) - return (-1); - - fs->n_devfd = open(fs->n_dev, O_RDONLY); - if (fs->n_devfd == -1) { - nandfs_seterr(fs, "couldn't open %s: %s", fs->n_dev, - strerror(errno)); - return (-1); - } - - return (0); -} - void nandfs_close(struct nandfs *fs) { @@ -294,18 +163,6 @@ nandfs_close(struct nandfs *fs) fs->n_flags &= ~NANDFS_IS_OPENED; } -void -nandfs_close_dev(struct nandfs *fs) -{ - - assert(fs->n_flags & NANDFS_IS_OPENED_DEV); - - close(fs->n_devfd); - fs->n_devfd = -1; - fs->n_flags &= ~NANDFS_IS_OPENED_DEV; - nandfs_close(fs); -} - static ssize_t nandfs_get_cpinfo(struct nandfs *fs, uint64_t cno, int mode, struct nandfs_cpinfo *cpinfo, size_t nci) @@ -349,8 +206,6 @@ nandfs_make_snap(struct nandfs *fs, uint { NANDFS_ASSERT_VALID(fs); - NANDFS_ASSERT_RDWR(fs); - NANDFS_ASSERT_LOCKED(fs); if (ioctl(fs->n_iocfd, NANDFS_IOCTL_MAKE_SNAP, cno) == -1) { nandfs_seterr(fs, "ioctl NANDFS_IOCTL_MAKE_SNAP: %s", @@ -366,8 +221,6 @@ nandfs_delete_snap(struct nandfs *fs, ui { NANDFS_ASSERT_VALID(fs); - NANDFS_ASSERT_RDWR(fs); - NANDFS_ASSERT_LOCKED(fs); if (ioctl(fs->n_iocfd, NANDFS_IOCTL_DELETE_SNAP, &cno) == -1) { nandfs_seterr(fs, "ioctl NANDFS_IOCTL_DELETE_SNAP: %s", Modified: projects/nand/sbin/nandfs/mksnap.c ============================================================================== --- projects/nand/sbin/nandfs/mksnap.c Sat Apr 7 05:25:13 2012 (r233983) +++ projects/nand/sbin/nandfs/mksnap.c Sat Apr 7 05:32:06 2012 (r233984) @@ -61,29 +61,18 @@ nandfs_mksnap(int argc, char **argv) } nandfs_init(&fs, argv[0]); - error = nandfs_open_rw(&fs); + error = nandfs_open(&fs); if (error == -1) { fprintf(stderr, "nandfs_open: %s\n", nandfs_errmsg(&fs)); goto out; } - error = nandfs_lock(&fs, 1); - if (error == -1) { - fprintf(stderr, "nandfs_lock: %s\n", nandfs_errmsg(&fs)); - goto out; - } - error = nandfs_make_snap(&fs, &cpno); if (error == -1) fprintf(stderr, "nandfs_make_snap: %s\n", nandfs_errmsg(&fs)); else printf("%jd\n", cpno); - error = nandfs_unlock(&fs); - if (error == -1) { - fprintf(stderr, "nandfs_unlock: %s\n", nandfs_errmsg(&fs)); - goto out; - } out: nandfs_close(&fs); nandfs_destroy(&fs); Modified: projects/nand/sbin/nandfs/rmsnap.c ============================================================================== --- projects/nand/sbin/nandfs/rmsnap.c Sat Apr 7 05:25:13 2012 (r233983) +++ projects/nand/sbin/nandfs/rmsnap.c Sat Apr 7 05:32:06 2012 (r233984) @@ -70,27 +70,16 @@ nandfs_rmsnap(int argc, char **argv) } nandfs_init(&fs, argv[1]); - error = nandfs_open_rw(&fs); + error = nandfs_open(&fs); if (error == -1) { fprintf(stderr, "nandfs_open: %s\n", nandfs_errmsg(&fs)); goto out; } - error = nandfs_lock(&fs, 1); - if (error == -1) { - fprintf(stderr, "nandfs_lock: %s\n", nandfs_errmsg(&fs)); - goto out; - } - error = nandfs_delete_snap(&fs, cpno); if (error == -1) fprintf(stderr, "nandfs_delete_snap: %s\n", nandfs_errmsg(&fs)); - error = nandfs_unlock(&fs); - if (error == -1) { - fprintf(stderr, "nandfs_unlock: %s\n", nandfs_errmsg(&fs)); - goto out; - } out: nandfs_close(&fs); nandfs_destroy(&fs);