ctdb: Use str_list_add_printf() in lock_helper_args()
[samba.git] / source3 / smbd / dfree.c
index 5b20707ffae87fd6a4bb092755a13c7d94aa6451..89dc11293b52bc814cb4c56ab3a134b5f6b7bba9 100644 (file)
@@ -51,16 +51,21 @@ static void disk_norm(uint64_t *bsize, uint64_t *dfree, uint64_t *dsize)
  Return number of 1K blocks available on a path and total number.
 ****************************************************************************/
 
-uint64_t sys_disk_free(connection_struct *conn, struct smb_filename *fname,
-                      uint64_t *bsize, uint64_t *dfree, uint64_t *dsize)
+static uint64_t sys_disk_free(connection_struct *conn,
+                             struct smb_filename *fname,
+                             uint64_t *bsize,
+                             uint64_t *dfree,
+                             uint64_t *dsize)
 {
+       const struct loadparm_substitution *lp_sub =
+               loadparm_s3_global_substitution();
        uint64_t dfree_retval;
        uint64_t dfree_q = 0;
        uint64_t bsize_q = 0;
        uint64_t dsize_q = 0;
        const char *dfree_command;
        static bool dfree_broken = false;
-       const char *path = fname->base_name;
+       char *path = fname->base_name;
 
        (*dfree) = (*dsize) = 0;
        (*bsize) = 512;
@@ -69,24 +74,27 @@ uint64_t sys_disk_free(connection_struct *conn, struct smb_filename *fname,
         * If external disk calculation specified, use it.
         */
 
-       dfree_command = lp_dfree_command(talloc_tos(), SNUM(conn));
+       dfree_command = lp_dfree_command(talloc_tos(), lp_sub, SNUM(conn));
        if (dfree_command && *dfree_command) {
                const char *p;
                char **lines = NULL;
-               char *syscmd = NULL;
+               char **argl = NULL;
 
-               syscmd = talloc_asprintf(talloc_tos(),
-                               "%s %s",
-                               dfree_command,
-                               path);
-
-               if (!syscmd) {
+               argl = str_list_make_empty(talloc_tos());
+               str_list_add_printf(&argl, "%s", dfree_command);
+               str_list_add_printf(&argl, "%s", path);
+               if (argl == NULL) {
                        return (uint64_t)-1;
                }
 
-               DEBUG (3, ("disk_free: Running command '%s'\n", syscmd));
+               DBG_NOTICE("Running command '%s %s'\n",
+                       dfree_command,
+                       path);
+
+               lines = file_lines_ploadv(talloc_tos(), argl, NULL);
+
+               TALLOC_FREE(argl);
 
-               lines = file_lines_pload(talloc_tos(), syscmd, NULL);
                if (lines != NULL) {
                        char *line = lines[0];
 
@@ -114,9 +122,9 @@ uint64_t sys_disk_free(connection_struct *conn, struct smb_filename *fname,
 
                        goto dfree_done;
                }
-               DEBUG (0, ("disk_free: file_lines_load() failed for "
-                          "command '%s'. Error was : %s\n",
-                          syscmd, strerror(errno) ));
+               DBG_ERR("file_lines_load() failed for "
+                          "command '%s %s'. Error was : %s\n",
+                          dfree_command, path, strerror(errno));
        }
 
        if (SMB_VFS_DISK_FREE(conn, fname, bsize, dfree, dsize) ==
@@ -172,9 +180,17 @@ dfree_done:
  Depending on the file system layout and file system features, the free space
  information can be different for different sub directories underneath a SMB
  share. Store the cache information in memcache using the query path as the
- key to accomodate this.
+ key to accommodate this.
 ****************************************************************************/
 
+struct dfree_cached_info {
+       time_t last_dfree_time;
+       uint64_t dfree_ret;
+       uint64_t bsize;
+       uint64_t dfree;
+       uint64_t dsize;
+};
+
 uint64_t get_dfree_info(connection_struct *conn, struct smb_filename *fname,
                        uint64_t *bsize, uint64_t *dfree, uint64_t *dsize)
 {
@@ -273,3 +289,8 @@ out:
        TALLOC_FREE(to_free);
        return dfree_ret;
 }
+
+void flush_dfree_cache(void)
+{
+       memcache_flush(smbd_memcache(), DFREE_CACHE);
+}