]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
add missing code to store_unlock so that the data that a client writes is stored...
authorRonnie sahlberg <ronniesahlberg@gmail.com>
Fri, 13 Apr 2007 10:37:41 +0000 (20:37 +1000)
committerRonnie sahlberg <ronniesahlberg@gmail.com>
Fri, 13 Apr 2007 10:37:41 +0000 (20:37 +1000)
this makes it possible to do fetch_lock and store_unlock across a domain socket to read/write data.

note that the actual locking is NOT implemented yet

(This used to be ctdb commit c7a397c56caf71283c081e5b97620085ed5108c6)

ctdb/common/ctdb_client.c
ctdb/common/ctdb_daemon.c
ctdb/tests/ctdb_fetch1.c

index fc6cefb7f9da319bad2921e18269557bcc58a98f..7e0bd10ce33402b6fb0c61bdcb6a1ae3a79a0693 100644 (file)
@@ -586,7 +586,7 @@ struct ctdb_call_state *ctdb_client_store_unlock_send(
   This is called when the program wants to wait for a ctdb_fetch_lock to complete and get the 
   results. This call will block unless the call has already completed.
 */
-struct ctdb_record_handle *ctdb_client_fetch_lock_recv(struct ctdb_call_state *state, TALLOC_CTX *mem_ctx, TDB_DATA key)
+struct ctdb_record_handle *ctdb_client_fetch_lock_recv(struct ctdb_call_state *state, TALLOC_CTX *mem_ctx, TDB_DATA key, TDB_DATA *data)
 {
        struct ctdb_record_handle *rec;
 
@@ -609,6 +609,9 @@ struct ctdb_record_handle *ctdb_client_fetch_lock_recv(struct ctdb_call_state *s
        rec->data->dsize = state->call.reply_data.dsize;
        rec->data->dptr  = talloc_memdup(rec, state->call.reply_data.dptr, rec->data->dsize);
 
+       if (data) {
+               *data = *rec->data;
+       }
        return rec;
 }
 
@@ -633,13 +636,14 @@ int ctdb_client_store_unlock_recv(struct ctdb_call_state *state, struct ctdb_rec
 
 struct ctdb_record_handle *ctdb_client_fetch_lock(struct ctdb_db_context *ctdb_db, 
                                                  TALLOC_CTX *mem_ctx, 
-                                                 TDB_DATA key, TDB_DATA *data)
+                                                 TDB_DATA key,
+                                                 TDB_DATA *data)
 {
        struct ctdb_call_state *state;
        struct ctdb_record_handle *rec;
 
        state = ctdb_client_fetch_lock_send(ctdb_db, mem_ctx, key);
-       rec = ctdb_client_fetch_lock_recv(state, mem_ctx, key);
+       rec = ctdb_client_fetch_lock_recv(state, mem_ctx, key, data);
 
        return rec;
 }
index b727bd62b237444c77c2f254b0da4818e533a1ba..c8baa7a70c7135de369850597d39dcefa0a2e6c9 100644 (file)
@@ -214,12 +214,36 @@ static void daemon_request_store_unlock(struct ctdb_client *client,
 {
        struct ctdb_db_context *ctdb_db;
        struct ctdb_reply_store_unlock r;
+       uint32_t caller = ctdb_get_vnn(client->ctdb);
+       struct ctdb_ltdb_header header;
+       TDB_DATA key, data;
        int res;
 
        ctdb_db = find_ctdb_db(client->ctdb, f->db_id);
+
        /* write the data to ltdb */
-/*XXX*/
+       key.dsize = f->keylen;
+       key.dptr  = &f->data[0];
+       res = ctdb_ltdb_fetch(ctdb_db, key, &header, NULL, NULL);
+       if (res) {
+               ctdb_set_error(ctdb_db->ctdb, "Fetch of locally held record failed");
+               res = -1;
+               goto done;
+       }
+       if (header.laccessor != caller) {
+               header.lacount = 0;
+       }
+       header.laccessor = caller;
+       header.lacount++;
+       data.dsize = f->datalen;
+       data.dptr  = &f->data[f->keylen];
+       res = ctdb_ltdb_store(ctdb_db, key, &header, data);
+       if ( res != 0) {
+               ctdb_set_error(ctdb_db->ctdb, "ctdb_call tdb_store failed\n");
+       }
 
+
+done:
        /* now send the reply */
        ZERO_STRUCT(r);
 
@@ -228,7 +252,7 @@ static void daemon_request_store_unlock(struct ctdb_client *client,
        r.hdr.ctdb_version = CTDB_VERSION;
        r.hdr.operation  = CTDB_REPLY_STORE_UNLOCK;
        r.hdr.reqid      = f->hdr.reqid;
-       r.state          = CTDB_CALL_DONE;
+       r.state          = res;
        
        res = ctdb_queue_send(client->queue, (uint8_t *)&r.hdr, r.hdr.length);
        if (res != 0) {
index 4e5bf63b6050047982298263af18b480aa61674f..60964882788abea7cf90b7222488644c288f8b2f 100644 (file)
@@ -42,7 +42,7 @@ int main(int argc, const char *argv[])
        const char *myaddress = NULL;
        int self_connect=0;
        int daemon_mode=0;
-       TDB_DATA key, *data, *data2, store_data;
+       TDB_DATA key, data, data2, store_data;
        struct ctdb_record_handle *rh;
 
        struct poptOption popt_options[] = {
@@ -137,26 +137,29 @@ int main(int argc, const char *argv[])
        ctdb_connect_wait(ctdb);
 
        key.dptr  = "Record";
-       key.dsize = strlen(key.dptr);
-       data      = NULL;
-       rh = ctdb_fetch_lock(ctdb_db, ctdb_db, key, data);
+       key.dsize = strlen(key.dptr)+1;
+       rh = ctdb_fetch_lock(ctdb_db, ctdb_db, key, &data);
 
        store_data.dptr  = "data to store";
        store_data.dsize = strlen(store_data.dptr)+1;
        ret = ctdb_store_unlock(rh, store_data);
-       printf("ctdb_store_unlock ret:%d\n",ret);
-
-       data2     = NULL;
-       rh = ctdb_fetch_lock(ctdb_db, ctdb_db, key, data2);
-/* hopefully   data2 will now contain the record written above */
 
+       rh = ctdb_fetch_lock(ctdb_db, ctdb_db, key, &data2);
+       /* hopefully   data2 will now contain the record written above */
+       if (!strcmp("data to store", data2.dptr)) {
+               printf("woohoo we read back the data we stored\n");
+       } else {
+               printf("ERROR: we read back different data than we stored\n");
+       }
+       
        /* just write it back to unlock it */
-       ret = ctdb_store_unlock(rh, data2);
-       printf("ctdb_store_unlock ret:%d\n",ret);
+       ret = ctdb_store_unlock(rh, store_data);
 
+#if 0
        while (1) {
                event_loop_once(ev);
        }
+#endif
 
        /* shut it down */
        talloc_free(ctdb);