AFS: Fix afs_prepare_write()
[safe/jmp/linux-2.6] / fs / afs / cmservice.c
index c3ec57a..d5b2ad6 100644 (file)
@@ -20,8 +20,12 @@ struct workqueue_struct *afs_cm_workqueue;
 
 static int afs_deliver_cb_init_call_back_state(struct afs_call *,
                                               struct sk_buff *, bool);
+static int afs_deliver_cb_init_call_back_state3(struct afs_call *,
+                                               struct sk_buff *, bool);
 static int afs_deliver_cb_probe(struct afs_call *, struct sk_buff *, bool);
 static int afs_deliver_cb_callback(struct afs_call *, struct sk_buff *, bool);
+static int afs_deliver_cb_get_capabilities(struct afs_call *, struct sk_buff *,
+                                          bool);
 static void afs_cm_destructor(struct afs_call *);
 
 /*
@@ -45,6 +49,16 @@ static const struct afs_call_type afs_SRXCBInitCallBackState = {
 };
 
 /*
+ * CB.InitCallBackState3 operation type
+ */
+static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
+       .name           = "CB.InitCallBackState3",
+       .deliver        = afs_deliver_cb_init_call_back_state3,
+       .abort_to_error = afs_abort_to_error,
+       .destructor     = afs_cm_destructor,
+};
+
+/*
  * CB.Probe operation type
  */
 static const struct afs_call_type afs_SRXCBProbe = {
@@ -55,6 +69,16 @@ static const struct afs_call_type afs_SRXCBProbe = {
 };
 
 /*
+ * CB.GetCapabilities operation type
+ */
+static const struct afs_call_type afs_SRXCBGetCapabilites = {
+       .name           = "CB.GetCapabilities",
+       .deliver        = afs_deliver_cb_get_capabilities,
+       .abort_to_error = afs_abort_to_error,
+       .destructor     = afs_cm_destructor,
+};
+
+/*
  * route an incoming cache manager call
  * - return T if supported, F if not
  */
@@ -71,9 +95,15 @@ bool afs_cm_incoming_call(struct afs_call *call)
        case CBInitCallBackState:
                call->type = &afs_SRXCBInitCallBackState;
                return true;
+       case CBInitCallBackState3:
+               call->type = &afs_SRXCBInitCallBackState3;
+               return true;
        case CBProbe:
                call->type = &afs_SRXCBProbe;
                return true;
+       case CBGetCapabilities:
+               call->type = &afs_SRXCBGetCapabilites;
+               return true;
        default:
                return false;
        }
@@ -297,6 +327,37 @@ static int afs_deliver_cb_init_call_back_state(struct afs_call *call,
 }
 
 /*
+ * deliver request data to a CB.InitCallBackState3 call
+ */
+static int afs_deliver_cb_init_call_back_state3(struct afs_call *call,
+                                               struct sk_buff *skb,
+                                               bool last)
+{
+       struct afs_server *server;
+       struct in_addr addr;
+
+       _enter(",{%u},%d", skb->len, last);
+
+       if (!last)
+               return 0;
+
+       /* no unmarshalling required */
+       call->state = AFS_CALL_REPLYING;
+
+       /* we'll need the file server record as that tells us which set of
+        * vnodes to operate upon */
+       memcpy(&addr, &ip_hdr(skb)->saddr, 4);
+       server = afs_find_server(&addr);
+       if (!server)
+               return -ENOTCONN;
+       call->server = server;
+
+       INIT_WORK(&call->work, SRXAFSCB_InitCallBackState);
+       schedule_work(&call->work);
+       return 0;
+}
+
+/*
  * allow the fileserver to see if the cache manager is still alive
  */
 static void SRXAFSCB_Probe(struct work_struct *work)
@@ -328,3 +389,87 @@ static int afs_deliver_cb_probe(struct afs_call *call, struct sk_buff *skb,
        schedule_work(&call->work);
        return 0;
 }
+
+/*
+ * allow the fileserver to ask about the cache manager's capabilities
+ */
+static void SRXAFSCB_GetCapabilities(struct work_struct *work)
+{
+       struct afs_interface *ifs;
+       struct afs_call *call = container_of(work, struct afs_call, work);
+       int loop, nifs;
+
+       struct {
+               struct /* InterfaceAddr */ {
+                       __be32 nifs;
+                       __be32 uuid[11];
+                       __be32 ifaddr[32];
+                       __be32 netmask[32];
+                       __be32 mtu[32];
+               } ia;
+               struct /* Capabilities */ {
+                       __be32 capcount;
+                       __be32 caps[1];
+               } cap;
+       } reply;
+
+       _enter("");
+
+       nifs = 0;
+       ifs = kcalloc(32, sizeof(*ifs), GFP_KERNEL);
+       if (ifs) {
+               nifs = afs_get_ipv4_interfaces(ifs, 32, false);
+               if (nifs < 0) {
+                       kfree(ifs);
+                       ifs = NULL;
+                       nifs = 0;
+               }
+       }
+
+       memset(&reply, 0, sizeof(reply));
+       reply.ia.nifs = htonl(nifs);
+
+       reply.ia.uuid[0] = htonl(afs_uuid.time_low);
+       reply.ia.uuid[1] = htonl(afs_uuid.time_mid);
+       reply.ia.uuid[2] = htonl(afs_uuid.time_hi_and_version);
+       reply.ia.uuid[3] = htonl((s8) afs_uuid.clock_seq_hi_and_reserved);
+       reply.ia.uuid[4] = htonl((s8) afs_uuid.clock_seq_low);
+       for (loop = 0; loop < 6; loop++)
+               reply.ia.uuid[loop + 5] = htonl((s8) afs_uuid.node[loop]);
+
+       if (ifs) {
+               for (loop = 0; loop < nifs; loop++) {
+                       reply.ia.ifaddr[loop] = ifs[loop].address.s_addr;
+                       reply.ia.netmask[loop] = ifs[loop].netmask.s_addr;
+                       reply.ia.mtu[loop] = htonl(ifs[loop].mtu);
+               }
+               kfree(ifs);
+       }
+
+       reply.cap.capcount = htonl(1);
+       reply.cap.caps[0] = htonl(AFS_CAP_ERROR_TRANSLATION);
+       afs_send_simple_reply(call, &reply, sizeof(reply));
+
+       _leave("");
+}
+
+/*
+ * deliver request data to a CB.GetCapabilities call
+ */
+static int afs_deliver_cb_get_capabilities(struct afs_call *call,
+                                          struct sk_buff *skb, bool last)
+{
+       _enter(",{%u},%d", skb->len, last);
+
+       if (skb->len > 0)
+               return -EBADMSG;
+       if (!last)
+               return 0;
+
+       /* no unmarshalling required */
+       call->state = AFS_CALL_REPLYING;
+
+       INIT_WORK(&call->work, SRXAFSCB_GetCapabilities);
+       schedule_work(&call->work);
+       return 0;
+}