From c41fb5f570072ede9b730c7addde3651061abd51 Mon Sep 17 00:00:00 2001 From: Andrew Klaassen Date: Fri, 4 May 2012 10:40:31 -0400 Subject: [PATCH] Add "cache locked write times" parameter. Supersedes previous patch. Compared to previous patch: - Adds manpage entry. - Brings up-to-date with git-latest. Andrew Klaassen --- .../smbdotconf/filename/cachelockedwritetimes.xml | 10 ++++++++++ lib/param/param_functions.c | 1 + source3/include/proto.h | 1 + source3/locking/locking.c | 5 +++-- source3/locking/proto.h | 3 ++- source3/param/loadparm.c | 10 ++++++++++ source3/smbd/dir.c | 2 +- source3/smbd/filename.c | 2 +- source3/smbd/nttrans.c | 4 ++-- source3/smbd/reply.c | 4 ++-- source3/smbd/smb2_create.c | 2 +- source3/smbd/smb2_getinfo.c | 4 ++-- source3/smbd/trans2.c | 8 ++++---- 13 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 docs-xml/smbdotconf/filename/cachelockedwritetimes.xml diff --git a/docs-xml/smbdotconf/filename/cachelockedwritetimes.xml b/docs-xml/smbdotconf/filename/cachelockedwritetimes.xml new file mode 100644 index 0000000..fe6d656 --- /dev/null +++ b/docs-xml/smbdotconf/filename/cachelockedwritetimes.xml @@ -0,0 +1,10 @@ + + + Setting this parameter to no prevents Samba from + caching write times. Defaults to yes. + +yes + diff --git a/lib/param/param_functions.c b/lib/param/param_functions.c index cd85cb0..fc8f104 100644 --- a/lib/param/param_functions.c +++ b/lib/param/param_functions.c @@ -157,3 +157,4 @@ FN_LOCAL_CHAR(magicchar, magic_char) FN_LOCAL_STRING(cups_options, szCupsOptions) FN_LOCAL_PARM_BOOL(change_notify, bChangeNotify) FN_LOCAL_PARM_BOOL(kernel_change_notify, bKernelChangeNotify) +FN_LOCAL_PARM_BOOL(cache_locked_write_times, bCacheLockedWriteTimes) diff --git a/source3/include/proto.h b/source3/include/proto.h index 686b230..8ec0b56 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -1231,6 +1231,7 @@ bool lp_client_use_spnego_principal(void); bool lp_hostname_lookups(void); bool lp_change_notify(const struct share_params *p ); bool lp_kernel_change_notify(const struct share_params *p ); +bool lp_cache_locked_write_times(const struct share_params *p ); const char * lp_dedicated_keytab_file(void); int lp_kerberos_method(void); bool lp_defer_sharing_violations(void); diff --git a/source3/locking/locking.c b/source3/locking/locking.c index b9afd23..ed04713 100644 --- a/source3/locking/locking.c +++ b/source3/locking/locking.c @@ -571,7 +571,8 @@ bool rename_share_filename(struct messaging_context *msg_ctx, return True; } -void get_file_infos(struct file_id id, +void get_file_infos(struct connection_struct *conn, + struct file_id id, uint32_t name_hash, bool *delete_on_close, struct timespec *write_time) @@ -594,7 +595,7 @@ void get_file_infos(struct file_id id, *delete_on_close = is_delete_on_close_set(lck, name_hash); } - if (write_time) { + if (write_time && lp_cache_locked_write_times(conn->params)) { struct timespec wt; wt = lck->data->changed_write_time; diff --git a/source3/locking/proto.h b/source3/locking/proto.h index 54badd9..48bd4c2 100644 --- a/source3/locking/proto.h +++ b/source3/locking/proto.h @@ -162,7 +162,8 @@ bool rename_share_filename(struct messaging_context *msg_ctx, uint32_t orig_name_hash, uint32_t new_name_hash, const struct smb_filename *smb_fname); -void get_file_infos(struct file_id id, +void get_file_infos(struct connection_struct *conn, + struct file_id id, uint32_t name_hash, bool *delete_on_close, struct timespec *write_time); diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index e781048..b6ac139 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -272,6 +272,7 @@ static struct loadparm_service sDefault = .bAclGroupControl = false, .bChangeNotify = true, .bKernelChangeNotify = true, + .bCacheLockedWriteTimes = true, .iallocation_roundup_size = SMB_ROUNDUP_ALLOCATION_SIZE, .iAioReadSize = 0, .iAioWriteSize = 0, @@ -1941,6 +1942,15 @@ static struct parm_struct parm_table[] = { .flags = FLAG_ADVANCED | FLAG_SHARE, }, { + .label = "cache locked write times", + .type = P_BOOL, + .p_class = P_LOCAL, + .offset = LOCAL_VAR(bCacheLockedWriteTimes), + .special = NULL, + .enum_list = NULL, + .flags = FLAG_ADVANCED | FLAG_SHARE, + }, + { .label = "lpq cache time", .type = P_INTEGER, .p_class = P_GLOBAL, diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index cb27110..d5e7176 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -1123,7 +1123,7 @@ bool smbd_dirptr_get_entry(TALLOC_CTX *ctx, fileid = vfs_file_id_from_sbuf(conn, &smb_fname.st); - get_file_infos(fileid, 0, NULL, &write_time_ts); + get_file_infos(conn, fileid, 0, NULL, &write_time_ts); if (!null_timespec(write_time_ts)) { update_stat_ex_mtime(&smb_fname.st, write_time_ts); diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c index ac218a1..42e0315 100644 --- a/source3/smbd/filename.c +++ b/source3/smbd/filename.c @@ -871,7 +871,7 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx, goto fail; } - get_file_infos(vfs_file_id_from_sbuf(conn, + get_file_infos(conn, vfs_file_id_from_sbuf(conn, &smb_fname->st), name_hash, &delete_pending, NULL); diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c index 168ef56..238d729 100644 --- a/source3/smbd/nttrans.c +++ b/source3/smbd/nttrans.c @@ -661,7 +661,7 @@ void reply_ntcreate_and_X(struct smb_request *req) /* Deal with other possible opens having a modified write time. JRA. */ ZERO_STRUCT(write_time_ts); - get_file_infos(fsp->file_id, 0, NULL, &write_time_ts); + get_file_infos(conn, fsp->file_id, 0, NULL, &write_time_ts); if (!null_timespec(write_time_ts)) { update_stat_ex_mtime(&smb_fname->st, write_time_ts); } @@ -1241,7 +1241,7 @@ static void call_nt_transact_create(connection_struct *conn, /* Deal with other possible opens having a modified write time. JRA. */ ZERO_STRUCT(write_time_ts); - get_file_infos(fsp->file_id, 0, NULL, &write_time_ts); + get_file_infos(conn, fsp->file_id, 0, NULL, &write_time_ts); if (!null_timespec(write_time_ts)) { update_stat_ex_mtime(&smb_fname->st, write_time_ts); } diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index dc43106..f52b769 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -1141,7 +1141,7 @@ void reply_getatr(struct smb_request *req) ZERO_STRUCT(write_time_ts); fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st); - get_file_infos(fileid, 0, NULL, &write_time_ts); + get_file_infos(conn, fileid, 0, NULL, &write_time_ts); if (!null_timespec(write_time_ts)) { update_stat_ex_mtime(&smb_fname->st, write_time_ts); } @@ -1812,7 +1812,7 @@ void reply_open(struct smb_request *req) struct timespec write_time_ts; ZERO_STRUCT(write_time_ts); - get_file_infos(fsp->file_id, 0, NULL, &write_time_ts); + get_file_infos(conn, fsp->file_id, 0, NULL, &write_time_ts); if (!null_timespec(write_time_ts)) { update_stat_ex_mtime(&smb_fname->st, write_time_ts); } diff --git a/source3/smbd/smb2_create.c b/source3/smbd/smb2_create.c index 35be328..76dfc29 100644 --- a/source3/smbd/smb2_create.c +++ b/source3/smbd/smb2_create.c @@ -805,7 +805,7 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx, /* Deal with other possible opens having a modified write time. JRA. */ ZERO_STRUCT(write_time_ts); - get_file_infos(result->file_id, 0, NULL, &write_time_ts); + get_file_infos(result->conn, result->file_id, 0, NULL, &write_time_ts); if (!null_timespec(write_time_ts)) { update_stat_ex_mtime(&result->fsp_name->st, write_time_ts); } diff --git a/source3/smbd/smb2_getinfo.c b/source3/smbd/smb2_getinfo.c index e8d918d..8cba0b8 100644 --- a/source3/smbd/smb2_getinfo.c +++ b/source3/smbd/smb2_getinfo.c @@ -355,7 +355,7 @@ static struct tevent_req *smbd_smb2_getinfo_send(TALLOC_CTX *mem_ctx, fileid = vfs_file_id_from_sbuf(conn, &fsp->fsp_name->st); - get_file_infos(fileid, fsp->name_hash, + get_file_infos(conn, fileid, fsp->name_hash, &delete_pending, &write_time_ts); } else { /* @@ -372,7 +372,7 @@ static struct tevent_req *smbd_smb2_getinfo_send(TALLOC_CTX *mem_ctx, } fileid = vfs_file_id_from_sbuf(conn, &fsp->fsp_name->st); - get_file_infos(fileid, fsp->name_hash, + get_file_infos(conn, fileid, fsp->name_hash, &delete_pending, &write_time_ts); } diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index 5cfbc31..dd27b7e 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -5142,7 +5142,7 @@ static void call_trans2qfilepathinfo(connection_struct *conn, } fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st); - get_file_infos(fileid, fsp->name_hash, &delete_pending, &write_time_ts); + get_file_infos(conn, fileid, fsp->name_hash, &delete_pending, &write_time_ts); } else { /* * Original code - this is an open file. @@ -5155,7 +5155,7 @@ static void call_trans2qfilepathinfo(connection_struct *conn, return; } fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st); - get_file_infos(fileid, fsp->name_hash, &delete_pending, &write_time_ts); + get_file_infos(conn, fileid, fsp->name_hash, &delete_pending, &write_time_ts); } } else { @@ -5266,7 +5266,7 @@ static void call_trans2qfilepathinfo(connection_struct *conn, fileid = vfs_file_id_from_sbuf(conn, &smb_fname_base->st); TALLOC_FREE(smb_fname_base); - get_file_infos(fileid, name_hash, &delete_pending, NULL); + get_file_infos(conn, fileid, name_hash, &delete_pending, NULL); if (delete_pending) { reply_nterror(req, NT_STATUS_DELETE_PENDING); return; @@ -5306,7 +5306,7 @@ static void call_trans2qfilepathinfo(connection_struct *conn, } fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st); - get_file_infos(fileid, name_hash, &delete_pending, &write_time_ts); + get_file_infos(conn, fileid, name_hash, &delete_pending, &write_time_ts); if (delete_pending) { reply_nterror(req, NT_STATUS_DELETE_PENDING); return; -- 1.7.9.1