diff options
author | Jeremy Allison <jra@samba.org> | 2005-07-22 01:14:09 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:00:15 -0500 |
commit | d6973499de8d70662178e9b558a3f5d2c70f203d (patch) | |
tree | f08bb42653dd46284fdbe714646e09cb72bdd9f0 /source3/smbd | |
parent | 58a3749e9c4393330c1c795b689ffb98c0aae381 (diff) | |
download | samba-d6973499de8d70662178e9b558a3f5d2c70f203d.tar.gz samba-d6973499de8d70662178e9b558a3f5d2c70f203d.tar.bz2 samba-d6973499de8d70662178e9b558a3f5d2c70f203d.zip |
r8695: Patch from James Peach for hires timestamps and efficient
notify code. Bugid #2285. The last commit by me on behalf
of James as he will be able to do his own now :-).
Jeremy.
(This used to be commit 524298b3f32f478e3750d805c5dc3b8fbe40d8d2)
Diffstat (limited to 'source3/smbd')
-rw-r--r-- | source3/smbd/notify_hash.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/source3/smbd/notify_hash.c b/source3/smbd/notify_hash.c index 08eefab652..ee7d4314ee 100644 --- a/source3/smbd/notify_hash.c +++ b/source3/smbd/notify_hash.c @@ -23,14 +23,28 @@ struct change_data { time_t last_check_time; /* time we last checked this entry */ +#ifdef HAVE_STAT_HIRES_TIMESTAMPS + struct timespec modify_time; + struct timespec status_time; +#else time_t modify_time; /* Info from the directory we're monitoring. */ time_t status_time; /* Info from the directory we're monitoring. */ +#endif time_t total_time; /* Total time of all directory entries - don't care if it wraps. */ unsigned int num_entries; /* Zero or the number of files in the directory. */ unsigned int mode_sum; unsigned char name_hash[16]; }; + +#ifdef HAVE_STAT_HIRES_TIMESTAMPS +/* Compare struct timespec. */ +#define TIMESTAMP_NEQ(x, y) (((x).tv_sec != (y).tv_sec) || ((x).tv_nsec != (y).tv_nsec)) +#else +/* Compare time_t . */ +#define TIMESTAMP_NEQ(x, y) ((x) != (y)) +#endif + /**************************************************************************** Create the hash we will use to determine if the contents changed. *****************************************************************************/ @@ -52,20 +66,36 @@ static BOOL notify_hash(connection_struct *conn, char *path, uint32 flags, if(SMB_VFS_STAT(conn,path, &st) == -1) return False; +#ifdef HAVE_STAT_HIRES_TIMESTAMPS + data->modify_time = st.st_mtim; + data->status_time = st.st_ctim; +#else data->modify_time = st.st_mtime; data->status_time = st.st_ctime; +#endif if (old_data) { /* * Shortcut to avoid directory scan if the time * has changed - we always must return true then. */ - if (old_data->modify_time != data->modify_time || - old_data->status_time != data->status_time ) { + if (TIMESTAMP_NEQ(old_data->modify_time, data->modify_time) || + TIMESTAMP_NEQ(old_data->status_time, data->status_time) ) { return True; } } + if (S_ISDIR(st.st_mode) && + (flags & ~(FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME)) == 0) + { + /* This is the case of a client wanting to know only when + * the contents of a directory changes. Since any file + * creation, rename or deletion will update the directory + * timestamps, we don't need to create a hash. + */ + return True; + } + /* * If we are to watch for changes that are only stored * in inodes of files, not in the directory inode, we must @@ -176,8 +206,8 @@ static BOOL hash_check_notify(connection_struct *conn, uint16 vuid, char *path, } if (!notify_hash(conn, path, flags, &data2, data) || - data2.modify_time != data->modify_time || - data2.status_time != data->status_time || + TIMESTAMP_NEQ(data2.modify_time, data->modify_time) || + TIMESTAMP_NEQ(data2.status_time, data->status_time) || data2.total_time != data->total_time || data2.num_entries != data->num_entries || data2.mode_sum != data->mode_sum || |