The kernel now has support for setting port&token of a query.

The fs_shell is now able to start up to 10 concurrent live queries. Use
"stopquery" to stop them all or just one of them, "startquery" to initiate
one, and "lsquery" to display them all.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3334 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2003-05-26 02:16:54 +00:00
parent b0ff9520c0
commit 6e14268838
3 changed files with 69 additions and 18 deletions

View File

@ -1061,26 +1061,66 @@ do_sync(int argc, char **argv)
}
void *gQueryCookie = NULL;
#define MAX_LIVE_QUERIES 10
void *gQueryCookie[MAX_LIVE_QUERIES] = {NULL};
char *gQueryString[MAX_LIVE_QUERIES] = {NULL};
static void
do_listqueries(int argc, char **argv)
{
int min, max;
if (argc == 2)
min = max = atol(argv[1]);
else {
min = 0;
max = MAX_LIVE_QUERIES - 1;
}
// list all queries (or only the one asked for)
for (; min <= max; min++) {
if (gQueryCookie[min] == NULL)
continue;
printf("%ld. (%p) %s\n", min, gQueryCookie[min], gQueryString[min]);
}
}
static void
do_stopquery(int argc, char **argv)
{
int err;
int min, max;
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;
if (argc == 2)
min = max = atol(argv[1]);
else {
min = 0;
max = MAX_LIVE_QUERIES - 1;
}
gQueryCookie = NULL;
// close all queries (or only the one asked for)
for (; min <= max; min++) {
if (gQueryCookie[min] == NULL)
continue;
err = sys_close_query(true, -1, "/myfs/.", gQueryCookie[min]);
if (err < 0) {
printf("could not close query: %s\n", strerror(err));
return;
}
gQueryCookie[min] = NULL;
free(gQueryString[min]);
}
}
@ -1088,10 +1128,17 @@ static void
do_startquery(int argc, char **argv)
{
char *query;
int freeSlot;
int err;
if (gQueryCookie != NULL)
do_stopquery(0, NULL);
for (freeSlot = 0; freeSlot < MAX_LIVE_QUERIES; freeSlot++) {
if (gQueryCookie[freeSlot] == NULL)
break;
}
if (freeSlot == MAX_LIVE_QUERIES) {
printf("All query slots are used, stop some\n");
return;
}
if (argc != 2) {
printf("query string expected\n");
@ -1099,12 +1146,14 @@ do_startquery(int argc, char **argv)
}
query = argv[1];
err = sys_open_query(true, -1, "/myfs/.", query, B_LIVE_QUERY, &gQueryCookie);
err = sys_open_query(true, -1, "/myfs/.", query, B_LIVE_QUERY, freeSlot, freeSlot, &gQueryCookie[freeSlot]);
if (err < 0) {
printf("could not open query: %s\n", strerror(err));
return;
} else
printf("query started - use the 'stopquery' command to stop it.\n");
}
printf("query number %ld started - use the 'stopquery' command to stop it.\n", freeSlot);
gQueryString[freeSlot] = strdup(query);
}
@ -1124,7 +1173,7 @@ do_query(int argc, char **argv)
}
query = argv[1];
err = sys_open_query(true, -1, "/myfs/.", query, 0, &cookie);
err = sys_open_query(true, -1, "/myfs/.", query, 0, 42, 42, &cookie);
if (err < 0) {
printf("could not open query: %s\n", strerror(err));
return;
@ -1357,6 +1406,7 @@ cmd_entry fsh_cmds[] =
{ "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" },
{ "lsquery", do_listqueries, "list all live queries" },
{ "ioctl", do_ioctl, "execute ioctl() without an inode (okay, with the root node)" },
{ "fcntl", do_fcntl, "execute ioctl() with the active inode" },
{ "cptest", do_copytest, "copies all files from the given path" },

View File

@ -1827,7 +1827,7 @@ error1:
int
sys_open_query(bool kernel, int fd, const char *path, const char *query, ulong flags, void **cookie)
sys_open_query(bool kernel, int fd, const char *path, const char *query, ulong flags, port_id port, ulong token, void **cookie)
{
int err;
nspace *ns;
@ -1848,7 +1848,7 @@ sys_open_query(bool kernel, int fd, const char *path, const char *query, ulong f
dec_vnode(root, FALSE);
return EPERM;
}
err = (*fs->ops.open_query)(ns->data, query, flags, -1, 0, cookie);
err = (*fs->ops.open_query)(ns->data, query, flags, port, token, cookie);
printf("sys_open_query() -- end: %d\n",err);
dec_vnode(root, FALSE);
@ -3203,7 +3203,7 @@ notify_listener(int op, nspace_id nsid, vnode_id vnida, vnode_id vnidb, vnode_id
text = "unknown operation...";
break;
}
printf("notify_listener: %s\n",text);
printf("notify_listener: %s\n", text);
#endif
return 0;
}
@ -3211,11 +3211,12 @@ notify_listener(int op, nspace_id nsid, vnode_id vnida, vnode_id vnidb, vnode_id
int
send_notification(port_id port, long token, ulong what, long op, nspace_id nsida,
nspace_id nsidb, vnode_id vnida,vnode_id vnidb, vnode_id vnidc,
nspace_id nsidb, vnode_id vnida, vnode_id vnidb, vnode_id vnidc,
const char *name)
{
#ifdef DEBUG
printf("send_notification... op = %s, name = %s\n",op == B_ENTRY_CREATED ? "B_ENTRY_CREATED" : "B_ENTRY_REMOVED",name);
printf("send_notification... op = %s, name = %s, port = %ld, token = %ld\n",
op == B_ENTRY_CREATED ? "B_ENTRY_CREATED" : "B_ENTRY_REMOVED", name, port, token);
#endif
return 0;
}

View File

@ -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_remove_attr(bool kernel, int fd, const char *name);
int sys_open_query(bool kernel, int fd, const char *path, const char *query, ulong flags, void **cookie);
int sys_open_query(bool kernel, int fd, const char *path, const char *query, ulong flags, port_id port, ulong token, 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);