pvfs: trigger a write time update 2 seconds after the first write
authorStefan Metzmacher <metze@samba.org>
Tue, 3 Jun 2008 09:36:08 +0000 (11:36 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 3 Jun 2008 12:03:50 +0000 (14:03 +0200)
metze

source/ntvfs/posix/pvfs_write.c

index 1f662f13fcdab52618bb4c5f07d8357dc9c57ef2..2da0e4bb3afc4f02c6915d5c967aca3414126551 100644 (file)
 #include "includes.h"
 #include "vfs_posix.h"
 #include "librpc/gen_ndr/security.h"
+#include "lib/events/events.h"
 
+static void pvfs_write_time_update_handler(struct event_context *ev,
+                                          struct timed_event *te,
+                                          struct timeval tv,
+                                          void *private_data)
+{
+       struct pvfs_file_handle *h = talloc_get_type(private_data,
+                                    struct pvfs_file_handle);
+       struct odb_lock *lck;
+       NTSTATUS status;
+       NTTIME write_time;
+
+       lck = odb_lock(h, h->pvfs->odb_context, &h->odb_locking_key);
+       if (lck == NULL) {
+               DEBUG(0,("Unable to lock opendb for write time update\n"));
+               return;
+       }
+
+       write_time = timeval_to_nttime(&tv);
+
+       status = odb_set_write_time(lck, write_time, false);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0,("Unable to update write time: %s\n",
+                       nt_errstr(status)));
+               return;
+       }
+
+       talloc_free(lck);
+
+       h->write_time.update_event = NULL;
+}
+
+static void pvfs_trigger_write_time_update(struct pvfs_file_handle *h)
+{
+       struct pvfs_state *pvfs = h->pvfs;
+       struct timeval tv;
+
+       if (h->write_time.update_triggered) {
+               return;
+       }
+
+       tv = timeval_current_ofs(0, pvfs->writetime_delay);
+
+       h->write_time.update_triggered = true;
+       h->write_time.update_on_close = true;
+       h->write_time.update_event = event_add_timed(pvfs->ntvfs->ctx->event_ctx,
+                                                    h, tv,
+                                                    pvfs_write_time_update_handler,
+                                                    h);
+       if (!h->write_time.update_event) {
+               DEBUG(0,("Failed event_add_timed\n"));
+       }
+}
 
 /*
   write to a file
@@ -61,6 +114,8 @@ NTSTATUS pvfs_write(struct ntvfs_module_context *ntvfs,
        status = pvfs_break_level2_oplocks(f);
        NT_STATUS_NOT_OK_RETURN(status);
 
+       pvfs_trigger_write_time_update(f->handle);
+
        if (f->handle->name->stream_name) {
                ret = pvfs_stream_write(pvfs,
                                        f->handle,