Staging: pohmelfs: sync with the development tree
authorEvgeniy Polyakov <zbr@ioremap.net>
Fri, 28 Aug 2009 13:57:58 +0000 (17:57 +0400)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 15 Sep 2009 19:02:30 +0000 (12:02 -0700)
* cache coherency protocol fix
 * proper timeout handling
 * implement dump/del all config group command
  (Signed-off-by: Pierpaolo Giacomin <yrz@anche.no>)

Signed-off-by: Evgeniy Polyakov <zbr@ioremap.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/pohmelfs/config.c
drivers/staging/pohmelfs/crypto.c
drivers/staging/pohmelfs/dir.c
drivers/staging/pohmelfs/inode.c
drivers/staging/pohmelfs/net.c
drivers/staging/pohmelfs/netfs.h
drivers/staging/pohmelfs/trans.c

index 99ae1d9649a0172b850ebf7a231f86f6c8ffabdb..90f962ee5fd8865a17622481a6a0d9c4e72d9966 100644 (file)
@@ -284,9 +284,91 @@ static int pohmelfs_cn_disp(struct cn_msg *msg)
                i += 1;
        }
 
+ out_unlock:
+       mutex_unlock(&pohmelfs_config_lock);
+       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;
+                               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;
+       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);
+                                       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)
@@ -350,7 +432,7 @@ static int pohmelfs_cn_ctl(struct cn_msg *msg, int action)
 
        list_add_tail(&c->config_entry, &g->config_list);
 
-out_unlock:
+ out_unlock:
        mutex_unlock(&pohmelfs_config_lock);
        if (pohmelfs_send_reply(err, 0, POHMELFS_NOINFO_ACK, msg, NULL))
                err = -ENOMEM;
@@ -408,7 +490,6 @@ static int pohmelfs_crypto_cipher_init(struct pohmelfs_config_group *g, struct p
        return 0;
 }
 
-
 static int pohmelfs_cn_crypto(struct cn_msg *msg)
 {
        struct pohmelfs_crypto *crypto = (struct pohmelfs_crypto *)msg->data;
@@ -456,9 +537,15 @@ static void pohmelfs_cn_callback(struct cn_msg *msg)
                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;
@@ -497,7 +584,8 @@ int pohmelfs_config_check(struct pohmelfs_config *config, int idx)
 
 int __init pohmelfs_config_init(void)
 {
-       return cn_add_callback(&pohmelfs_cn_id, "pohmelfs", pohmelfs_cn_callback);
+       /* XXX remove (void *) cast when vanilla connector got synced */
+       return cn_add_callback(&pohmelfs_cn_id, "pohmelfs", (void *)pohmelfs_cn_callback);
 }
 
 void pohmelfs_config_exit(void)
index 19781ad782fb3a2562d4b72a4ddbd9c7b3c6b648..884183c0913a9eee0cce7a853760cafe587f9510 100644 (file)
@@ -176,7 +176,7 @@ static int pohmelfs_crypto_process(struct ablkcipher_request *req,
                                        timeout);
                        if (!err)
                                err = -ETIMEDOUT;
-                       else
+                       else if (err > 0)
                                err = complete.error;
                        break;
                default:
@@ -738,7 +738,7 @@ static int pohmelfs_crypto_init_handshake(struct pohmelfs_sb *psb)
                        psb->wait_on_page_timeout);
        if (!err)
                err = -ETIMEDOUT;
-       else
+       else if (err > 0)
                err = -psb->flags;
 
        if (!err)
index 4c63a4cc1bd4c52456dbda9462db03a9ff8a60a1..6c5b261e9f0683dd5f0b1c361f8a9ea2be225db0 100644 (file)
@@ -352,7 +352,9 @@ static int pohmelfs_sync_remote_dir(struct pohmelfs_inode *pi)
                        test_bit(NETFS_INODE_REMOTE_DIR_SYNCED, &pi->state) || pi->error, ret);
        dprintk("%s: awake dir: %llu, ret: %ld, err: %d.\n", __func__, pi->ino, ret, pi->error);
        if (ret <= 0) {
-               err = -ETIMEDOUT;
+               err = ret;
+               if (!err)
+                       err = -ETIMEDOUT;
                goto err_out_exit;
        }
 
@@ -472,10 +474,11 @@ static int pohmelfs_lookup_single(struct pohmelfs_inode *parent,
        err = 0;
        ret = wait_event_interruptible_timeout(psb->wait,
                        !test_bit(NETFS_COMMAND_PENDING, &parent->state), ret);
-       if (ret == 0)
-               err = -ETIMEDOUT;
-       else if (signal_pending(current))
-               err = -EINTR;
+       if (ret <= 0) {
+               err = ret;
+               if (!err)
+                       err = -ETIMEDOUT;
+       }
 
        if (err)
                goto err_out_exit;
@@ -505,13 +508,21 @@ struct dentry *pohmelfs_lookup(struct inode *dir, struct dentry *dentry, struct
        struct pohmelfs_name *n;
        struct inode *inode = NULL;
        unsigned long ino = 0;
-       int err, lock_type = POHMELFS_READ_LOCK, need_lock;
+       int err, lock_type = POHMELFS_READ_LOCK, need_lock = 1;
        struct qstr str = dentry->d_name;
 
        if ((nd->intent.open.flags & O_ACCMODE) > 1)
                lock_type = POHMELFS_WRITE_LOCK;
 
-       need_lock = pohmelfs_need_lock(parent, lock_type);
+       if (test_bit(NETFS_INODE_OWNED, &parent->state)) {
+               if (lock_type == parent->lock_type)
+                       need_lock = 0;
+               if ((lock_type == POHMELFS_READ_LOCK) && (parent->lock_type == POHMELFS_WRITE_LOCK))
+                       need_lock = 0;
+       }
+
+       if ((lock_type == POHMELFS_READ_LOCK) && !test_bit(NETFS_INODE_REMOTE_DIR_SYNCED, &parent->state))
+               need_lock = 1;
 
        str.hash = jhash(dentry->d_name.name, dentry->d_name.len, 0);
 
index 0b58f10437079761d9ea5cbbd16b36694fc19691..c94de31392239932590c227679963346425d1c5d 100644 (file)
@@ -1504,7 +1504,9 @@ static void pohmelfs_flush_inode(struct pohmelfs_inode *pi, unsigned int count)
                inode->i_sb->s_op->write_inode(inode, 0);
        }
 
+#ifdef POHMELFS_TRUNCATE_ON_INODE_FLUSH
        truncate_inode_pages(inode->i_mapping, 0);
+#endif
 
        pohmelfs_data_unlock(pi, 0, ~0, POHMELFS_WRITE_LOCK);
        mutex_unlock(&inode->i_mutex);
@@ -1743,11 +1745,10 @@ static int pohmelfs_root_handshake(struct pohmelfs_sb *psb)
        err = wait_event_interruptible_timeout(psb->wait,
                        (psb->flags != ~0),
                        psb->wait_on_page_timeout);
-       if (!err) {
+       if (!err)
                err = -ETIMEDOUT;
-       } else {
+       else if (err > 0)
                err = -psb->flags;
-       }
 
        if (err)
                goto err_out_exit;
index bdaab6905fdeacab0ae54fcf4609e1f20175b52a..af7f262e68c2040e86440d845055a08c6d2f8b46 100644 (file)
@@ -1005,13 +1005,12 @@ int netfs_state_init(struct netfs_state *st)
 
        if (st->socket->ops->family == AF_INET) {
                struct sockaddr_in *sin = (struct sockaddr_in *)&ctl->addr;
-               printk(KERN_INFO "%s: (re)connected to peer %u.%u.%u.%u:%d.\n", __func__,
-                       NIPQUAD(sin->sin_addr.s_addr), ntohs(sin->sin_port));
+               printk(KERN_INFO "%s: (re)connected to peer %pi4:%d.\n", __func__,
+                       &sin->sin_addr.s_addr, ntohs(sin->sin_port));
        } else if (st->socket->ops->family == AF_INET6) {
                struct sockaddr_in6 *sin = (struct sockaddr_in6 *)&ctl->addr;
-               printk(KERN_INFO "%s: (re)connected to peer "
-                       "%pi6:%d",
-                       __func__, &sin->sin6_addr, ntohs(sin->sin6_port));
+               printk(KERN_INFO "%s: (re)connected to peer %pi6:%d", __func__,
+                               &sin->sin6_addr, ntohs(sin->sin6_port));
        }
 
        return 0;
@@ -1031,13 +1030,12 @@ void netfs_state_exit(struct netfs_state *st)
 
                if (st->socket->ops->family == AF_INET) {
                        struct sockaddr_in *sin = (struct sockaddr_in *)&st->ctl.addr;
-                       printk("%s: disconnected from peer %u.%u.%u.%u:%d.\n", __func__,
-                               NIPQUAD(sin->sin_addr.s_addr), ntohs(sin->sin_port));
+                       printk(KERN_INFO "%s: disconnected from peer %pi4:%d.\n", __func__,
+                               &sin->sin_addr.s_addr, ntohs(sin->sin_port));
                } else if (st->socket->ops->family == AF_INET6) {
                        struct sockaddr_in6 *sin = (struct sockaddr_in6 *)&st->ctl.addr;
-                       printk("%s: disconnected from peer "
-                               "%pi6:%d",
-                               __func__, &sin->sin6_addr, ntohs(sin->sin6_port));
+                       printk(KERN_INFO "%s: disconnected from peer %pi6:%d", __func__,
+                               &sin->sin6_addr, ntohs(sin->sin6_port));
                }
 
                sock_release(st->socket);
index 3b60c611ba805e142713d8e440a5cb400f6b3586..623a07d29dea3da2ec4e061e892b242add6e73f2 100644 (file)
@@ -25,6 +25,7 @@
 #define POHMELFS_CTLINFO_ACK           1
 #define POHMELFS_NOINFO_ACK            2
 
+#define POHMELFS_NULL_IDX              65535
 
 /*
  * Network command structure.
@@ -87,6 +88,8 @@ enum {
        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 */
 };
 
 /*
@@ -905,6 +908,8 @@ static inline void pohmelfs_mcache_put(struct pohmelfs_sb *psb,
                pohmelfs_mcache_free(psb, m);
 }
 
+//#define POHMELFS_TRUNCATE_ON_INODE_FLUSH
+
 #endif /* __KERNEL__*/
 
 #endif /* __NETFS_H */
index 4587f6d546aacf998881c54d8a7c0e063fc6fab1..36a253582565629403c86265428977eaea96e20d 100644 (file)
@@ -468,7 +468,8 @@ int netfs_trans_finish_send(struct netfs_trans *t, struct pohmelfs_sb *psb)
                                continue;
                }
 
-               if (psb->active_state && (psb->active_state->state.ctl.prio >= st->ctl.prio))
+               if (psb->active_state && (psb->active_state->state.ctl.prio >= st->ctl.prio) &&
+                               (t->flags & NETFS_TRANS_SINGLE_DST))
                        st = &psb->active_state->state;
 
                err = netfs_trans_push(t, st);