new_vnode() now complains if the vnode already exists (and panics with when

it has a different data set).
Improved the kernel's PANIC() function (now accepts varargs).
sys_open_query() now has a flags field (that can be set to B_LIVE_QUERY).
The fs_shell now supports one live query; might be enhanced later to support
more than just one (concurrently).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3318 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2003-05-25 16:56:03 +00:00
parent 8e2f0a9a0a
commit a1fe805b79
3 changed files with 95 additions and 15 deletions
@@ -24,6 +24,7 @@
#include "argv.h" #include "argv.h"
#include <fs_attr.h> #include <fs_attr.h>
#include <fs_query.h>
static void do_lat_fs(int argc, char **argv); static void do_lat_fs(int argc, char **argv);
static void do_fsh(void); static void do_fsh(void);
@@ -1060,6 +1061,50 @@ do_sync(int argc, char **argv)
} }
void *gQueryCookie = NULL;
static void
do_stopquery(int argc, char **argv)
{
int err;
if (gQueryCookie == NULL) {
printf("no query running (use the 'startquery' command to start a query).\n");
return;
}
err = sys_close_query(true, -1, "/myfs/.", gQueryCookie);
if (err < 0) {
printf("could not close query: %s\n", strerror(err));
return;
}
gQueryCookie = NULL;
}
static void
do_startquery(int argc, char **argv)
{
char *query;
int err;
if (argc != 2) {
printf("query string expected");
return;
}
query = argv[1];
err = sys_open_query(true, -1, "/myfs/.", query, B_LIVE_QUERY, &gQueryCookie);
if (err < 0) {
printf("could not open query: %s\n", strerror(err));
return;
} else
printf("query started - use the 'stopquery' command to stop it.");
}
static void static void
do_query(int argc, char **argv) do_query(int argc, char **argv)
{ {
@@ -1076,7 +1121,7 @@ do_query(int argc, char **argv)
} }
query = argv[1]; query = argv[1];
err = sys_open_query(true,-1,"/myfs/.",query,&cookie); err = sys_open_query(true, -1, "/myfs/.", query, 0, &cookie);
if (err < 0) { if (err < 0) {
printf("could not open query: %s\n", strerror(err)); printf("could not open query: %s\n", strerror(err));
return; return;
@@ -1307,6 +1352,8 @@ cmd_entry fsh_cmds[] =
{ "create", do_create, "create N files. default is 100" }, { "create", do_create, "create N files. default is 100" },
{ "delete", do_delete, "delete N files. default is 100" }, { "delete", do_delete, "delete N files. default is 100" },
{ "query", do_query, "run a query on the file system" }, { "query", do_query, "run a query on the file system" },
{ "startquery", do_startquery, "run a live query on the file system" },
{ "stopquery", do_stopquery, "stops the live query" },
{ "ioctl", do_ioctl, "execute ioctl() without an inode (okay, with the root node)" }, { "ioctl", do_ioctl, "execute ioctl() without an inode (okay, with the root node)" },
{ "fcntl", do_fcntl, "execute ioctl() with the active inode" }, { "fcntl", do_fcntl, "execute ioctl() with the active inode" },
{ "cptest", do_copytest, "copies all files from the given path" }, { "cptest", do_copytest, "copies all files from the given path" },
@@ -215,9 +215,15 @@ static int free_fds(fdarray *fds);
#include <stdio.h> #include <stdio.h>
static void static void
PANIC(char *s) PANIC(char *s, ...)
{ {
printf(s); va_list list;
va_start(list, s);
vfprintf(stdout, s, list);
va_end(list);
exit(-1);
} }
@@ -1821,7 +1827,7 @@ error1:
int int
sys_open_query(bool kernel, int fd, const char *path, const char *query, void **cookie) sys_open_query(bool kernel, int fd, const char *path, const char *query, ulong flags, void **cookie)
{ {
int err; int err;
nspace *ns; nspace *ns;
@@ -1842,7 +1848,7 @@ sys_open_query(bool kernel, int fd, const char *path, const char *query, void **
dec_vnode(root, FALSE); dec_vnode(root, FALSE);
return EPERM; return EPERM;
} }
err = (*fs->ops.open_query)(ns->data, query, 0, -1, 0, cookie); err = (*fs->ops.open_query)(ns->data, query, flags, -1, 0, cookie);
printf("sys_open_query() -- end: %d\n",err); printf("sys_open_query() -- end: %d\n",err);
dec_vnode(root, FALSE); dec_vnode(root, FALSE);
@@ -2232,10 +2238,37 @@ put_vnode(nspace_id nsid, vnode_id vnid)
int int
new_vnode(nspace_id nsid, vnode_id vnid, void *data) new_vnode(nspace_id nsid, vnode_id vnid, void *data)
{ {
int err; int retries = 20;
vnode *vn; vnode *vn;
int err;
LOCK(vnlock); LOCK(vnlock);
restart:
if ((vn = lookup_vnode(nsid, vnid)) != NULL) {
// oh, we requested a new vnode although there already
// exist one - compare the private node data and bail
// out if needed.
if (vn->busy) {
printf("new_vnode(): vnode exists and is busy!\n");
snooze(500);
if (retries-- >= 0)
goto restart;
printf("new_vnode(): still busy, but continue to our doom!\n");
}
if (vn->data != data)
PANIC("new_vnode(): vnode already exists with different data (vnode id = %Ld)!\n", vnid);
else {
printf("new_vnode(): vnode already exists with the same data (vnode id = %Ld)\n", vnid);
vn->rcnt++;
return;
UNLOCK(vnlock);
}
}
vn = steal_vnode(FREE_LIST); vn = steal_vnode(FREE_LIST);
if (!vn) { if (!vn) {
vn = steal_vnode(USED_LIST); vn = steal_vnode(USED_LIST);
@@ -43,7 +43,7 @@ ssize_t sys_read_attr(bool kernel, int fd, const char *name, int type, void *buf
ssize_t sys_write_attr(bool kernel, int fd, const char *name, int type, void *buffer, size_t len, off_t pos); ssize_t sys_write_attr(bool kernel, int fd, const char *name, int type, void *buffer, size_t len, off_t pos);
ssize_t sys_remove_attr(bool kernel, int fd, const char *name); ssize_t sys_remove_attr(bool kernel, int fd, const char *name);
int sys_open_query(bool kernel, int fd, const char *path, const char *query, void **cookie); int sys_open_query(bool kernel, int fd, const char *path, const char *query, ulong flags, void **cookie);
int sys_close_query(bool kernel, int fd, const char *path, void *cookie); int sys_close_query(bool kernel, int fd, const char *path, void *cookie);
int sys_read_query(bool kernel, int fd, const char *path, void *cookie,struct dirent *dent,size_t bufferSize,long num); int sys_read_query(bool kernel, int fd, const char *path, void *cookie,struct dirent *dent,size_t bufferSize,long num);