Dear All,

in attachment you can find a patch for pohmelfs module
(pohmelfs_kernel_y.patch) and a patch for the cfg tool
(pohmelfs_cfg_y.patch).
These patches enables two new commands in the cfg tool.
dump (syntax cfg -A dump)
this command is equivalent to the show command but for all active indexes.

and flush (syntax cfg -A flush or cfg -A flush -i index)
this command is equivalent to del but allow you to delete all entries, or
in the case of the -i parameter all entries for a given index.
the reply of the command is the same for dump.

In order to enable the first one without messing with the choice of an
unsigned int for idx I choose arbitrary a POHMELFS_NULL_IDX (defined in
netfs.h). If you try to use directly in the cfg tool such an index you are
warned and stopped.

Moreover I've a couple of questions. 
1. For the flush command I followed the same policy of the action "del" in
pohmelfs_cn_ctl (config.c): i delete each entry and i don't check if the
config_group is empty nor i delete it in the case. Is it be the right
behaviour? In this case where a config_group is deleted if empty?
2. Isn't passing all arguments even for delete a bit... unconvenient?
Woulnd't be better to have two levels of indexes?

Finally... thank you for pohmelfs :)

cheers,
pierpaolo

On Wed, 5 Aug 2009 00:14:02 +0400, Evgeniy Polyakov <[email protected]>
wrote:
> Hi Pierpaolo.
> 
> On Tue, Aug 04, 2009 at 08:00:27PM +0000, pierpaolo giacomin
([email protected])
> wrote:
>> I added to cfg (and in the kernel module) a dump action in order to show
>> all configuration index.
>> Are interested in such a functionality?
>> 
>> Let me know if you want me to provide patches.
> 
> Please send them to me and [email protected] mail list, if patches
> are good, I will merge them in the tree and upstream.
diff -urN linux-2.6.30.4.y/drivers/staging/pohmelfs/config.c 
linux-2.6.30.4/drivers/staging/pohmelfs/config.c
--- linux-2.6.30.4.y/drivers/staging/pohmelfs/config.c  2009-08-05 
14:40:32.000000000 +0300
+++ linux-2.6.30.4/drivers/staging/pohmelfs/config.c    2009-07-31 
01:34:47.000000000 +0300
@@ -289,92 +289,6 @@
         return err;
 }
 
-static int pohmelfs_cn_dump(struct cn_msg *msg)
-{
-       struct pohmelfs_config_group *g;
-       struct pohmelfs_config *c, *tmp;
-       int err = 0, i = 1;
-       int total_msg = 0;
-
-       if (msg->len != sizeof(struct pohmelfs_ctl))
-               return -EBADMSG;
-
-       mutex_lock(&pohmelfs_config_lock);
-
-       list_for_each_entry(g, &pohmelfs_config_list, group_entry) {
-               if(g) total_msg += g->num_entry;
-       }
-       if(total_msg == 0) {
-               if (pohmelfs_send_reply(err, 0, POHMELFS_NOINFO_ACK, msg, NULL))
-                       err = -ENOMEM;
-               goto out_unlock;
-       }
-
-       list_for_each_entry(g, &pohmelfs_config_list, group_entry) {
-               if(g) {
-                       list_for_each_entry_safe(c, tmp, &g->config_list, 
config_entry) {
-                               struct pohmelfs_ctl *sc = &c->state.ctl;
-                               printk("sending back a line of Config index 
%d\n", sc->idx);
-                               if (pohmelfs_send_reply(err, total_msg - i, 
POHMELFS_CTLINFO_ACK, msg, sc)) {
-                                       err = -ENOMEM;
-                                       goto out_unlock;
-                               }
-                               i += 1;
-                       }
-               }
-       }
-
-out_unlock:
-        mutex_unlock(&pohmelfs_config_lock);
-        return err;
-}
-
-static int pohmelfs_cn_flush(struct cn_msg *msg)
-{
-       struct pohmelfs_config_group *g;
-       struct pohmelfs_ctl *ctl = (struct pohmelfs_ctl *)msg->data;
-       struct pohmelfs_config *c, *tmp;
-       int err = 0;
-
-       if (msg->len != sizeof(struct pohmelfs_ctl))
-               return -EBADMSG;
-
-       mutex_lock(&pohmelfs_config_lock);
-       
-       if(ctl->idx != POHMELFS_NULL_IDX)
-       {
-               g = pohmelfs_find_config_group(ctl->idx);
-
-               if (!g) {
-                       goto out_unlock;
-               }
-               list_for_each_entry_safe(c, tmp, &g->config_list, config_entry) 
{
-                       list_del(&c->config_entry);
-                       g->num_entry--;
-                       kfree(c);
-               }
-       }
-       else {
-               list_for_each_entry(g, &pohmelfs_config_list, group_entry) {
-                       if(g) {
-                               list_for_each_entry_safe(c, tmp, 
&g->config_list, config_entry) {
-                                       list_del(&c->config_entry);
-                                       printk("g->num_entry <%d>\n", 
g->num_entry);
-                                       g->num_entry--;
-                                       kfree(c);
-                               }
-                       }
-               }
-       }
-
-
-out_unlock:
-        mutex_unlock(&pohmelfs_config_lock);
-       pohmelfs_cn_dump(msg);
-
-        return err;
-}
-
 static int pohmelfs_modify_config(struct pohmelfs_ctl *old, struct 
pohmelfs_ctl *new)
 {
        old->perm = new->perm;
@@ -543,15 +457,9 @@
                case POHMELFS_FLAGS_MODIFY:
                        err = pohmelfs_cn_ctl(msg, msg->flags);
                        break;
-               case POHMELFS_FLAGS_FLUSH:
-                       err = pohmelfs_cn_flush(msg);
-                       break;
                case POHMELFS_FLAGS_SHOW:
                        err = pohmelfs_cn_disp(msg);
                        break;
-               case POHMELFS_FLAGS_DUMP:
-                       err = pohmelfs_cn_dump(msg);
-                       break;
                case POHMELFS_FLAGS_CRYPTO:
                        err = pohmelfs_cn_crypto(msg);
                        break;
diff -urN linux-2.6.30.4.y/drivers/staging/pohmelfs/netfs.h 
linux-2.6.30.4/drivers/staging/pohmelfs/netfs.h
--- linux-2.6.30.4.y/drivers/staging/pohmelfs/netfs.h   2009-08-05 
13:13:43.000000000 +0300
+++ linux-2.6.30.4/drivers/staging/pohmelfs/netfs.h     2009-07-31 
01:34:47.000000000 +0300
@@ -25,7 +25,6 @@
 #define POHMELFS_CTLINFO_ACK           1
 #define POHMELFS_NOINFO_ACK            2
 
-#define POHMELFS_NULL_IDX              65535
 
 /*
  * Network command structure.
@@ -89,8 +88,6 @@
        POHMELFS_FLAGS_SHOW,    /* Network state control message for SHOW */
        POHMELFS_FLAGS_CRYPTO,  /* Crypto data control message */
        POHMELFS_FLAGS_MODIFY,  /* Network state modification message */
-       POHMELFS_FLAGS_DUMP,    /* Network state control message for SHOW ALL */
-       POHMELFS_FLAGS_FLUSH,   /* Network state control message for FLUSH */
 };
 
 /*
--- pohmelfs-server.y/cfg/cfg.c 2009-08-05 14:49:18.000000000 +0300
+++ pohmelfs-server/cfg/cfg.c   2009-08-05 14:50:37.000000000 +0300
@@ -53,15 +53,12 @@
 static void pohmelfs_display_function(struct pohmelfs_ctl *ctl)
 {
        static int display_banner;
-       static unsigned int last_config_index;
        struct sockaddr_in *sa;
        struct sockaddr_in6 *sa6;
        struct in6_addr *in6;
        struct sockaddr *saddr;
        char inet6_addr[128];
 
-       if (last_config_index != ctl->idx) display_banner = 0;
-       
        if (!display_banner) {
                printf("Config Index = %d\n", ctl->idx);
                printf("Family    Server IP                                     
       Port     \n");
@@ -141,7 +138,7 @@
                                errno = ack->error;
                                if(errno)
                                        return errno;
-                               if (flags == POHMELFS_FLAGS_SHOW || 
POHMELFS_FLAGS_DUMP) {
+                               if (flags == POHMELFS_FLAGS_SHOW) {
                                         pohmelfs_display_function(&ack->ctl);
                                }
                                if (!ack->msg_num)
@@ -255,29 +252,6 @@
        return err;
 }
 
-static int pohmelfs_dump_remote(int s)
-{
-       struct pohmelfs_ctl ctl;
-       int err;
-       memset(&ctl, 0, sizeof(struct pohmelfs_ctl));
-       err =  pohmelfs_netlink_send(s, POHMELFS_FLAGS_DUMP, 
-                       &ctl, sizeof(struct pohmelfs_ctl));
-
-       return err;
-}
-
-static int pohmelfs_flush_remote(int s, unsigned int idx)
-{
-       struct pohmelfs_ctl ctl;
-       int err;
-       memset(&ctl, 0, sizeof(struct pohmelfs_ctl));
-       ctl.idx = idx;
-       err =  pohmelfs_netlink_send(s, POHMELFS_FLAGS_FLUSH, 
-                       &ctl, sizeof(struct pohmelfs_ctl));
-
-       return err;
-}
-
 static int pohmelfs_add_remote(int s, char *addr, int port, unsigned int idx, 
int perm, int prio, int action)
 {
        int err;
@@ -328,21 +302,20 @@
 
 static void pohmelfs_usage(char *p)
 {
-       fprintf(stderr, "Usage: %s -A[ction] {add/del/show/modify/dump/flush} 
-a[ddress] {ipv4/ipv6} -p[ort] -i[ndex]"
+       fprintf(stderr, "Usage: %s -A[ction] {add/del/show/modify} -a[ddress] 
{ipv4/ipv6} -p[ort] -i[ndex]"
                " -k[cipher_key_file] -K [hash_key_file] -C[ipher] -H[ash] 
-P[riority] -I[nput/output permissions] -h\n", p);
-       fprintf(stderr, "\tindex %d reserved as null idx\n", POHMELFS_NULL_IDX);
 }
 
 int main(int argc, char *argv[])
 {
        int ch, port, err, s, prio, perm;
-       int idx;
+       unsigned int idx;
        char *addr, *action, *cipher_key, *hash_key, *cipher, *hash;
        struct sockaddr_nl l_local;
 
        addr = NULL;
        port = -1;
-       idx = POHMELFS_NULL_IDX;
+       idx = 0;
        action = cipher_key = hash_key = cipher = hash = NULL;
        perm = POHMELFS_IO_PERM_READ | POHMELFS_IO_PERM_WRITE;
        prio = 0;
@@ -361,11 +334,6 @@
                                prio = atoi(optarg);
                                break;
                        case 'i':
-                               if(atoi(optarg) == POHMELFS_NULL_IDX)
-                               {
-                                       pohmelfs_usage(argv[0]);
-                                       return -1;
-                               }
                                idx = atoi(optarg);
                                break;
                        case 'C':
@@ -422,11 +390,6 @@
        err = -EINVAL;
 
        if (action) {
-               if (strncmp(action, "flush", 5)) {
-                       if(idx == -1)
-                               idx = 0;
-               }
-       
                if (!strncmp(action, "add", 3)) {
                        if (addr && port != -1)
                                err = pohmelfs_add_remote(s, addr, port, idx, 
perm, prio, POHMELFS_FLAGS_ADD);
@@ -456,14 +419,6 @@
                                if (err)
                                        goto out;
                        }
-               } else if (!strncmp(action, "dump", 4)) {
-                       err = pohmelfs_dump_remote(s);
-                       if (err)
-                               goto out;
-               } else if (!strncmp(action, "flush", 5)) {
-                       err = pohmelfs_flush_remote(s, idx);
-                       if (err)
-                               goto out;
                } else if (!strncmp(action, "modify", 6)) {
                        err = pohmelfs_add_remote(s, addr, port, idx, perm, 
prio, POHMELFS_FLAGS_MODIFY);
                        if (err)
_______________________________________________
Pohmelfs mailing list
[email protected]
http://www.ioremap.net/cgi-bin/mailman/listinfo/pohmelfs

Reply via email to