[sheepdog] [PATCH] add const where appropriate

MORITA Kazutaka morita.kazutaka at gmail.com
Tue Sep 3 18:57:05 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 dog/cluster.c       |    6 ++--
 dog/dog.c           |   10 +++----
 dog/dog.h           |    8 +++---
 dog/node.c          |    2 +-
 dog/trace.c         |    2 +-
 dog/vdi.c           |    4 +--
 include/option.h    |    2 +-
 include/util.h      |    6 ++--
 lib/util.c          |    6 ++--
 sheep/md.c          |   76 +++++++++++++++++++++++++++------------------------
 sheep/plain_store.c |   70 +++++++++++++++++++++++++----------------------
 sheep/request.c     |    2 +-
 sheep/sheep.c       |   18 ++++++------
 sheep/sheep_priv.h  |   16 +++++------
 14 files changed, 119 insertions(+), 109 deletions(-)

diff --git a/dog/cluster.c b/dog/cluster.c
index 3fd87bd..026b425 100644
--- a/dog/cluster.c
+++ b/dog/cluster.c
@@ -220,7 +220,7 @@ static void print_list(void *buf, unsigned len)
 
 static int list_snapshot(int argc, char **argv)
 {
-	char *path = argv[optind++];
+	const char *path = argv[optind++];
 	void *buf = NULL;
 	int log_nr;
 	int ret = EXIT_SYSFAIL;
@@ -274,7 +274,7 @@ static void fill_object_tree(uint32_t vid, const char *name, const char *tag,
 
 static int save_snapshot(int argc, char **argv)
 {
-	char *tag = argv[optind++];
+	const char *tag = argv[optind++];
 	char *path, *p;
 	int ret = EXIT_SYSFAIL, uninitialized_var(unused);
 
@@ -514,7 +514,7 @@ static struct subcommand cluster_cmd[] = {
 	{NULL,},
 };
 
-static int cluster_parser(int ch, char *opt)
+static int cluster_parser(int ch, const char *opt)
 {
 	int copies;
 	char *p;
diff --git a/dog/dog.c b/dog/dog.c
index cca8e66..b2c56ff 100644
--- a/dog/dog.c
+++ b/dog/dog.c
@@ -99,12 +99,12 @@ out:
 	return ret;
 }
 
-static int (*command_parser)(int, char *);
+static int (*command_parser)(int, const char *);
 static int (*command_fn)(int, char **);
 static const char *command_opts;
 static const char *command_arg;
 static const char *command_desc;
-static struct sd_option *command_options;
+static const struct sd_option *command_options;
 
 static const struct sd_option *find_opt(int ch)
 {
@@ -170,11 +170,11 @@ static const struct subcommand *find_subcmd(const char *cmd, const char *subcmd)
 }
 
 static unsigned long setup_commands(const struct command *commands,
-				    char *cmd, char *subcmd)
+				    const char *cmd, const char *subcmd)
 {
 	int i;
 	bool found = false;
-	struct subcommand *s;
+	const struct subcommand *s;
 	unsigned long flags = 0;
 
 	for (i = 0; commands[i].name; i++) {
@@ -223,7 +223,7 @@ static unsigned long setup_commands(const struct command *commands,
 static void usage(const struct command *commands, int status)
 {
 	int i;
-	struct subcommand *s;
+	const struct subcommand *s;
 	char name[64];
 
 	if (status)
diff --git a/dog/dog.h b/dog/dog.h
index f155724..97cfb0d 100644
--- a/dog/dog.h
+++ b/dog/dog.h
@@ -33,8 +33,8 @@
 
 struct command {
 	const char *name;
-	struct subcommand *sub;
-	int (*parser)(int, char *);
+	const struct subcommand *sub;
+	int (*parser)(int, const char *);
 };
 
 struct subcommand {
@@ -42,10 +42,10 @@ struct subcommand {
 	const char *arg;
 	const char *opts;
 	const char *desc;
-	struct subcommand *sub;
+	const struct subcommand *sub;
 	unsigned long flags;
 	int (*fn)(int, char **);
-	struct sd_option *options;
+	const struct sd_option *options;
 };
 void subcommand_usage(char *cmd, char *subcmd, int status);
 
diff --git a/dog/node.c b/dog/node.c
index 886c012..5a6a62c 100644
--- a/dog/node.c
+++ b/dog/node.c
@@ -417,7 +417,7 @@ static int node_md(int argc, char **argv)
 }
 
 
-static int node_parser(int ch, char *opt)
+static int node_parser(int ch, const char *opt)
 {
 	switch (ch) {
 	case 'A':
diff --git a/dog/trace.c b/dog/trace.c
index 7c57c7d..5da1353 100644
--- a/dog/trace.c
+++ b/dog/trace.c
@@ -342,7 +342,7 @@ static int graph_stat(int argc, char **argv)
 	return EXIT_SUCCESS;
 }
 
-static int trace_parser(int ch, char *opt)
+static int trace_parser(int ch, const char *opt)
 {
 	return 0;
 }
diff --git a/dog/vdi.c b/dog/vdi.c
index 4601140..041e441 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -746,7 +746,7 @@ static int do_vdi_delete(const char *vdiname, int snap_id, const char *snap_tag)
 
 static int vdi_delete(int argc, char **argv)
 {
-	char *vdiname = argv[optind];
+	const char *vdiname = argv[optind];
 
 	return do_vdi_delete(vdiname, vdi_cmd_data.snapshot_id,
 			     vdi_cmd_data.snapshot_tag);
@@ -2102,7 +2102,7 @@ static struct subcommand vdi_cmd[] = {
 	{NULL,},
 };
 
-static int vdi_parser(int ch, char *opt)
+static int vdi_parser(int ch, const char *opt)
 {
 	char *p;
 	int nr_copies;
diff --git a/include/option.h b/include/option.h
index ba62496..738cc88 100644
--- a/include/option.h
+++ b/include/option.h
@@ -24,7 +24,7 @@ struct sd_option {
 
 struct option_parser {
 	const char *option;
-	int (*parser)(char *);
+	int (*parser)(const char *);
 };
 
 char *build_short_options(const struct sd_option *opts);
diff --git a/include/util.h b/include/util.h
index f82e13d..fb59192 100644
--- a/include/util.h
+++ b/include/util.h
@@ -104,8 +104,8 @@ int eventfd_xread(int efd);
 void eventfd_xwrite(int efd, int value);
 void pstrcpy(char *buf, int buf_size, const char *str);
 char *chomp(char *str);
-int rmdir_r(char *dir_path);
-int purge_directory(char *dir_path);
+int rmdir_r(const char *dir_path);
+int purge_directory(const char *dir_path);
 bool is_numeric(const char *p);
 int install_sighandler(int signum, void (*handler)(int), bool once);
 int install_crash_handler(void (*handler)(int));
@@ -119,7 +119,7 @@ void find_zero_blocks(const void *buf, uint64_t *poffset, uint32_t *plen);
 void trim_zero_blocks(void *buf, uint64_t *offset, uint32_t *len);
 void untrim_zero_blocks(void *buf, uint64_t offset, uint32_t len,
 			uint32_t requested_len);
-int atomic_create_and_write(const char *path, char *buf, size_t len,
+int atomic_create_and_write(const char *path, const char *buf, size_t len,
 			    bool force_create);
 
 /* a type safe version of qsort() */
diff --git a/lib/util.c b/lib/util.c
index 2519e4e..7c7785d 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -341,7 +341,7 @@ char *chomp(char *str)
 }
 
 /* Purge directory recursively */
-int purge_directory(char *dir_path)
+int purge_directory(const char *dir_path)
 {
 	int ret = 0;
 	struct stat s;
@@ -383,7 +383,7 @@ out:
 }
 
 /* remove directory recursively */
-int rmdir_r(char *dir_path)
+int rmdir_r(const char *dir_path)
 {
 	int ret;
 
@@ -576,7 +576,7 @@ const char *my_exe_path(void)
  * If force_create is true, this function create the file even when the
  * temporary file exists.
  */
-int atomic_create_and_write(const char *path, char *buf, size_t len,
+int atomic_create_and_write(const char *path, const char *buf, size_t len,
 			    bool force_create)
 {
 	int fd, ret;
diff --git a/sheep/md.c b/sheep/md.c
index ba73c40..b79fde4 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -54,7 +54,7 @@ static inline int nr_online_disks(void)
 	return nr;
 }
 
-static inline int vdisk_number(struct disk *disk)
+static inline int vdisk_number(const struct disk *disk)
 {
 	return DIV_ROUND_UP(disk->space, MD_VDISK_SIZE);
 }
@@ -102,20 +102,22 @@ static inline void trim_last_slash(char *path)
 		path[strlen(path) - 1] = '\0';
 }
 
-static struct disk *path_to_disk(char *path)
+static struct disk *path_to_disk(const char *path)
 {
 	struct disk *disk;
+	char p[PATH_MAX];
 
-	trim_last_slash(path);
+	pstrcpy(p, sizeof(p), path);
+	trim_last_slash(p);
 	list_for_each_entry(disk, &md.disk_list, list) {
-		if (strcmp(disk->path, path) == 0)
+		if (strcmp(disk->path, p) == 0)
 			return disk;
 	}
 
 	return NULL;
 }
 
-static int get_total_object_size(uint64_t oid, char *wd, uint32_t epoch,
+static int get_total_object_size(uint64_t oid, const char *wd, uint32_t epoch,
 				 void *total)
 {
 	uint64_t *t = total;
@@ -132,8 +134,8 @@ static int get_total_object_size(uint64_t oid, char *wd, uint32_t epoch,
 }
 
 /* If cleanup is true, temporary objects will be removed */
-static int for_each_object_in_path(char *path,
-				   int (*func)(uint64_t, char *, uint32_t,
+static int for_each_object_in_path(const char *path,
+				   int (*func)(uint64_t, const char *, uint32_t,
 					       void *),
 				   bool cleanup, void *arg)
 {
@@ -182,7 +184,7 @@ static int for_each_object_in_path(char *path,
 	return ret;
 }
 
-static uint64_t get_path_free_size(char *path, uint64_t *used)
+static uint64_t get_path_free_size(const char *path, uint64_t *used)
 {
 	struct statvfs fs;
 	uint64_t size;
@@ -207,7 +209,7 @@ out:
  * safely use 0 to represent failure case  because 0 space path can be
  * considered as broken path.
  */
-static uint64_t init_path_space(char *path)
+static uint64_t init_path_space(const char *path)
 {
 	uint64_t size;
 	char stale[PATH_MAX];
@@ -249,7 +251,7 @@ broken_path:
 }
 
 /* We don't need lock at init stage */
-bool md_add_disk(char *path)
+bool md_add_disk(const char *path)
 {
 	struct disk *new;
 
@@ -302,7 +304,7 @@ uint64_t md_init_space(void)
 
 static const char *md_get_object_path_nolock(uint64_t oid)
 {
-	struct vdisk *vd;
+	const struct vdisk *vd;
 
 	if (unlikely(md.nr_disks == 0))
 		return NONE_EXIST_PATH; /* To generate EIO */
@@ -322,12 +324,12 @@ const char *md_get_object_path(uint64_t oid)
 	return p;
 }
 
-int for_each_object_in_wd(int (*func)(uint64_t oid, char *path, uint32_t epoch,
-				      void *arg),
+int for_each_object_in_wd(int (*func)(uint64_t oid, const char *path,
+				      uint32_t epoch, void *arg),
 			  bool cleanup, void *arg)
 {
 	int ret = SD_RES_SUCCESS;
-	struct disk *disk;
+	const struct disk *disk;
 
 	sd_read_lock(&md.lock);
 	list_for_each_entry(disk, &md.disk_list, list) {
@@ -339,13 +341,13 @@ int for_each_object_in_wd(int (*func)(uint64_t oid, char *path, uint32_t epoch,
 	return ret;
 }
 
-int for_each_object_in_stale(int (*func)(uint64_t oid, char *path,
+int for_each_object_in_stale(int (*func)(uint64_t oid, const char *path,
 					 uint32_t epoch, void *arg),
 			     void *arg)
 {
 	int ret = SD_RES_SUCCESS;
 	char path[PATH_MAX];
-	struct disk *disk;
+	const struct disk *disk;
 
 	sd_read_lock(&md.lock);
 	list_for_each_entry(disk, &md.disk_list, list) {
@@ -359,10 +361,10 @@ int for_each_object_in_stale(int (*func)(uint64_t oid, char *path,
 }
 
 
-int for_each_obj_path(int (*func)(char *path))
+int for_each_obj_path(int (*func)(const char *path))
 {
 	int ret = SD_RES_SUCCESS;
-	struct disk *disk;
+	const struct disk *disk;
 
 	sd_read_lock(&md.lock);
 	list_for_each_entry(disk, &md.disk_list, list) {
@@ -409,7 +411,7 @@ out:
 	free(mw);
 }
 
-int md_handle_eio(char *fault_path)
+int md_handle_eio(const char *fault_path)
 {
 	struct md_work *mw;
 
@@ -425,7 +427,7 @@ int md_handle_eio(char *fault_path)
 	return SD_RES_NETWORK_ERROR;
 }
 
-static inline bool md_access(char *path)
+static inline bool md_access(const char *path)
 {
 	if (access(path, R_OK | W_OK) < 0) {
 		if (unlikely(errno != ENOENT))
@@ -436,17 +438,18 @@ static inline bool md_access(char *path)
 	return true;
 }
 
-static int get_old_new_path(uint64_t oid, uint32_t epoch, char *path,
-			    char *old, char *new)
+static int get_old_new_path(uint64_t oid, uint32_t epoch, const char *path,
+			    char *old, size_t old_size, char *new,
+			    size_t new_size)
 {
 	if (!epoch) {
-		snprintf(old, PATH_MAX, "%s/%016" PRIx64, path, oid);
-		snprintf(new, PATH_MAX, "%s/%016" PRIx64,
+		snprintf(old, old_size, "%s/%016" PRIx64, path, oid);
+		snprintf(new, new_size, "%s/%016" PRIx64,
 			 md_get_object_path_nolock(oid), oid);
 	} else {
-		snprintf(old, PATH_MAX, "%s/.stale/%016"PRIx64".%"PRIu32, path,
+		snprintf(old, old_size, "%s/.stale/%016"PRIx64".%"PRIu32, path,
 			 oid, epoch);
-		snprintf(new, PATH_MAX, "%s/.stale/%016"PRIx64".%"PRIu32,
+		snprintf(new, new_size, "%s/.stale/%016"PRIx64".%"PRIu32,
 			 md_get_object_path_nolock(oid), oid, epoch);
 	}
 
@@ -456,7 +459,7 @@ static int get_old_new_path(uint64_t oid, uint32_t epoch, char *path,
 	return 0;
 }
 
-static int md_move_object(uint64_t oid, char *old, char *new)
+static int md_move_object(uint64_t oid, const char *old, const char *new)
 {
 	struct strbuf buf = STRBUF_INIT;
 	int fd, ret = -1;
@@ -489,11 +492,12 @@ out:
 	return ret;
 }
 
-static int md_check_and_move(uint64_t oid, uint32_t epoch, char *path)
+static int md_check_and_move(uint64_t oid, uint32_t epoch, const char *path)
 {
 	char old[PATH_MAX], new[PATH_MAX];
 
-	if (get_old_new_path(oid, epoch, path, old, new) < 0)
+	if (get_old_new_path(oid, epoch, path, old, sizeof(old), new,
+			     sizeof(new)) < 0)
 		return SD_RES_EIO;
 	/*
 	 * Recovery thread and main thread might try to recover the same object.
@@ -517,7 +521,7 @@ static int md_check_and_move(uint64_t oid, uint32_t epoch, char *path)
 static int scan_wd(uint64_t oid, uint32_t epoch)
 {
 	int ret = SD_RES_EIO;
-	struct disk *disk;
+	const struct disk *disk;
 
 	sd_read_lock(&md.lock);
 	list_for_each_entry(disk, &md.disk_list, list) {
@@ -548,9 +552,9 @@ bool md_exist(uint64_t oid)
 	return false;
 }
 
-int md_get_stale_path(uint64_t oid, uint32_t epoch, char *path)
+int md_get_stale_path(uint64_t oid, uint32_t epoch, char *path, size_t size)
 {
-	snprintf(path, PATH_MAX, "%s/.stale/%016"PRIx64".%"PRIu32,
+	snprintf(path, size, "%s/.stale/%016"PRIx64".%"PRIu32,
 		 md_get_object_path(oid), oid, epoch);
 	if (md_access(path))
 		return SD_RES_SUCCESS;
@@ -565,7 +569,7 @@ int md_get_stale_path(uint64_t oid, uint32_t epoch, char *path)
 uint32_t md_get_info(struct sd_md_info *info)
 {
 	uint32_t ret = sizeof(*info);
-	struct disk *disk;
+	const struct disk *disk;
 	int i = 0;
 
 	memset(info, 0, ret);
@@ -583,7 +587,7 @@ uint32_t md_get_info(struct sd_md_info *info)
 	return ret;
 }
 
-static inline void md_del_disk(char *path)
+static inline void md_del_disk(const char *path)
 {
 	struct disk *disk = path_to_disk(path);
 
@@ -596,7 +600,7 @@ static inline void md_del_disk(char *path)
 
 static int do_plug_unplug(char *disks, bool plug)
 {
-	char *path;
+	const char *path;
 	int old_nr, ret = SD_RES_UNKNOWN;
 
 	sd_write_lock(&md.lock);
@@ -638,7 +642,7 @@ int md_unplug_disks(char *disks)
 uint64_t md_get_size(uint64_t *used)
 {
 	uint64_t fsize = 0;
-	struct disk *disk;
+	const struct disk *disk;
 
 	*used = 0;
 	sd_read_lock(&md.lock);
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 3dc3944..7cba585 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -38,21 +38,22 @@ static int prepare_iocb(uint64_t oid, const struct siocb *iocb, bool create)
 	return flags;
 }
 
-static int get_obj_path(uint64_t oid, char *path)
+static int get_obj_path(uint64_t oid, char *path, size_t size)
 {
-	return snprintf(path, PATH_MAX, "%s/%016" PRIx64,
+	return snprintf(path, size, "%s/%016" PRIx64,
 			md_get_object_path(oid), oid);
 }
 
-static int get_tmp_obj_path(uint64_t oid, char *path)
+static int get_tmp_obj_path(uint64_t oid, char *path, size_t size)
 {
-	return snprintf(path, PATH_MAX, "%s/%016"PRIx64".tmp",
+	return snprintf(path, size, "%s/%016"PRIx64".tmp",
 			md_get_object_path(oid), oid);
 }
 
-static int get_stale_obj_path(uint64_t oid, uint32_t epoch, char *path)
+static int get_stale_obj_path(uint64_t oid, uint32_t epoch, char *path,
+			      size_t size)
 {
-	return md_get_stale_path(oid, epoch, path);
+	return md_get_stale_path(oid, epoch, path, size);
 }
 
 bool default_exist(uint64_t oid)
@@ -60,10 +61,14 @@ bool default_exist(uint64_t oid)
 	return md_exist(oid);
 }
 
-static int err_to_sderr(char *path, uint64_t oid, int err)
+static int err_to_sderr(const char *path, uint64_t oid, int err)
 {
 	struct stat s;
-	char *dir = dirname(path);
+	char p[PATH_MAX], *dir;
+
+	/* Use a temporary buffer since dirname() may modify its argument. */
+	pstrcpy(p, sizeof(p), path);
+	dir = dirname(p);
 
 	sd_debug("%s", dir);
 	switch (err) {
@@ -114,7 +119,7 @@ int default_write(uint64_t oid, const struct siocb *iocb)
 		sync();
 	}
 
-	get_obj_path(oid, path);
+	get_obj_path(oid, path, sizeof(path));
 
 	fd = open(path, flags, sd_def_fmode);
 	if (unlikely(fd < 0))
@@ -133,7 +138,7 @@ out:
 	return ret;
 }
 
-static int make_stale_dir(char *path)
+static int make_stale_dir(const char *path)
 {
 	char p[PATH_MAX];
 
@@ -145,7 +150,7 @@ static int make_stale_dir(char *path)
 	return SD_RES_SUCCESS;
 }
 
-static int purge_dir(char *path)
+static int purge_dir(const char *path)
 {
 	if (purge_directory(path) < 0)
 		return SD_RES_EIO;
@@ -153,7 +158,7 @@ static int purge_dir(char *path)
 	return SD_RES_SUCCESS;
 }
 
-static int purge_stale_dir(char *path)
+static int purge_stale_dir(const char *path)
 {
 	char p[PATH_MAX];
 
@@ -172,7 +177,7 @@ int default_cleanup(void)
 	return SD_RES_SUCCESS;
 }
 
-static int init_vdi_state(uint64_t oid, char *wd, uint32_t epoch)
+static int init_vdi_state(uint64_t oid, const char *wd, uint32_t epoch)
 {
 	int ret;
 	struct sd_inode *inode = xzalloc(SD_INODE_HEADER_SIZE);
@@ -199,8 +204,8 @@ out:
 	return SD_RES_SUCCESS;
 }
 
-static int init_objlist_and_vdi_bitmap(uint64_t oid, char *wd, uint32_t epoch,
-				       void *arg)
+static int init_objlist_and_vdi_bitmap(uint64_t oid, const char *wd,
+				       uint32_t epoch, void *arg)
 {
 	int ret;
 	objlist_cache_insert(oid);
@@ -228,7 +233,7 @@ int default_init(void)
 	return for_each_object_in_wd(init_objlist_and_vdi_bitmap, true, NULL);
 }
 
-static int default_read_from_path(uint64_t oid, char *path,
+static int default_read_from_path(uint64_t oid, const char *path,
 				  const struct siocb *iocb)
 {
 	int flags = prepare_iocb(oid, iocb, false), fd,
@@ -256,7 +261,7 @@ int default_read(uint64_t oid, const struct siocb *iocb)
 	int ret;
 	char path[PATH_MAX];
 
-	get_obj_path(oid, path);
+	get_obj_path(oid, path, sizeof(path));
 	ret = default_read_from_path(oid, path, iocb);
 
 	/*
@@ -265,7 +270,7 @@ int default_read(uint64_t oid, const struct siocb *iocb)
 	 */
 	if (ret == SD_RES_NO_OBJ && iocb->epoch > 0 &&
 	    iocb->epoch < sys_epoch()) {
-		get_stale_obj_path(oid, iocb->epoch, path);
+		get_stale_obj_path(oid, iocb->epoch, path, sizeof(path));
 		ret = default_read_from_path(oid, path, iocb);
 	}
 
@@ -295,8 +300,8 @@ int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 	int ret, fd;
 	uint32_t len = iocb->length;
 
-	get_obj_path(oid, path);
-	get_tmp_obj_path(oid, tmp_path);
+	get_obj_path(oid, path, sizeof(path));
+	get_tmp_obj_path(oid, tmp_path, sizeof(tmp_path));
 
 	if (uatomic_is_true(&sys->use_journal) &&
 	    journal_write_store(oid, iocb->buf, iocb->length,
@@ -363,8 +368,8 @@ int default_link(uint64_t oid, uint32_t tgt_epoch)
 	sd_debug("try link %"PRIx64" from snapshot with epoch %d", oid,
 		 tgt_epoch);
 
-	get_obj_path(oid, path);
-	get_stale_obj_path(oid, tgt_epoch, stale_path);
+	get_obj_path(oid, path, sizeof(path));
+	get_stale_obj_path(oid, tgt_epoch, stale_path, sizeof(stale_path));
 
 	if (link(stale_path, path) < 0) {
 		/*
@@ -406,8 +411,8 @@ static bool oid_stale(uint64_t oid)
 	return ret;
 }
 
-static int move_object_to_stale_dir(uint64_t oid, char *wd, uint32_t epoch,
-				    void *arg)
+static int move_object_to_stale_dir(uint64_t oid, const char *wd,
+				    uint32_t epoch, void *arg)
 {
 	char path[PATH_MAX], stale_path[PATH_MAX];
 	uint32_t tgt_epoch = *(int *)arg;
@@ -426,7 +431,7 @@ static int move_object_to_stale_dir(uint64_t oid, char *wd, uint32_t epoch,
 	return SD_RES_SUCCESS;
 }
 
-static int check_stale_objects(uint64_t oid, char *wd, uint32_t epoch,
+static int check_stale_objects(uint64_t oid, const char *wd, uint32_t epoch,
 			       void *arg)
 {
 	if (oid_stale(oid))
@@ -463,7 +468,7 @@ int default_remove_object(uint64_t oid)
 	if (uatomic_is_true(&sys->use_journal))
 		journal_remove_object(oid);
 
-	get_obj_path(oid, path);
+	get_obj_path(oid, path, sizeof(path));
 
 	if (unlink(path) < 0) {
 		if (errno == ENOENT)
@@ -478,7 +483,7 @@ int default_remove_object(uint64_t oid)
 
 #define SHA1NAME "user.obj.sha1"
 
-static int get_object_sha1(char *path, uint8_t *sha1)
+static int get_object_sha1(const char *path, uint8_t *sha1)
 {
 	if (getxattr(path, SHA1NAME, sha1, SHA1_DIGEST_SIZE)
 	    != SHA1_DIGEST_SIZE) {
@@ -492,7 +497,7 @@ static int get_object_sha1(char *path, uint8_t *sha1)
 	return 0;
 }
 
-static int set_object_sha1(char *path, const uint8_t *sha1)
+static int set_object_sha1(const char *path, const uint8_t *sha1)
 {
 	int ret;
 
@@ -503,12 +508,13 @@ static int set_object_sha1(char *path, const uint8_t *sha1)
 	return ret;
 }
 
-static int get_object_path(uint64_t oid, uint32_t epoch, char *path)
+static int get_object_path(uint64_t oid, uint32_t epoch, char *path,
+			   size_t size)
 {
 	if (default_exist(oid)) {
-		get_obj_path(oid, path);
+		get_obj_path(oid, path, size);
 	} else {
-		get_stale_obj_path(oid, epoch, path);
+		get_stale_obj_path(oid, epoch, path, size);
 		if (access(path, F_OK) < 0) {
 			if (errno == ENOENT)
 				return SD_RES_NO_OBJ;
@@ -529,7 +535,7 @@ int default_get_hash(uint64_t oid, uint32_t epoch, uint8_t *sha1)
 	bool is_readonly_obj = oid_is_readonly(oid);
 	char path[PATH_MAX];
 
-	ret = get_object_path(oid, epoch, path);
+	ret = get_object_path(oid, epoch, path, sizeof(path));
 	if (ret != SD_RES_SUCCESS)
 		return ret;
 
diff --git a/sheep/request.c b/sheep/request.c
index c8e0022..5bd917b 100644
--- a/sheep/request.c
+++ b/sheep/request.c
@@ -835,7 +835,7 @@ static int create_listen_port_fn(int fd, void *data)
 	return register_event(fd, listen_handler, data);
 }
 
-int create_listen_port(char *bindaddr, int port)
+int create_listen_port(const char *bindaddr, int port)
 {
 	static bool is_inet_socket = true;
 
diff --git a/sheep/sheep.c b/sheep/sheep.c
index db131c6..7d4cd85 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -260,7 +260,7 @@ static void crash_handler(int signo)
 static struct system_info __sys;
 struct system_info *sys = &__sys;
 
-static int cache_size_parser(char *s)
+static int cache_size_parser(const char *s)
 {
 	const uint64_t max_cache_size = ((uint64_t)UINT32_MAX + 1)*1024*1024;
 	uint64_t cache_size;
@@ -279,7 +279,7 @@ static int cache_size_parser(char *s)
 	return 0;
 }
 
-static int cache_directio_parser(char *s)
+static int cache_directio_parser(const char *s)
 {
 	sys->object_cache_directio = true;
 	return 0;
@@ -287,7 +287,7 @@ static int cache_directio_parser(char *s)
 
 static char ocpath[PATH_MAX];
 
-static int cache_dir_parser(char *s)
+static int cache_dir_parser(const char *s)
 {
 	snprintf(ocpath, sizeof(ocpath), "%s", s);
 	return 0;
@@ -300,14 +300,14 @@ static struct option_parser cache_parsers[] = {
 	{ NULL, NULL },
 };
 
-static char *io_addr, *io_pt;
-static int ionic_host_parser(char *s)
+static const char *io_addr, *io_pt;
+static int ionic_host_parser(const char *s)
 {
 	io_addr = s;
 	return 0;
 }
 
-static int ionic_port_parser(char *s)
+static int ionic_port_parser(const char *s)
 {
 	io_pt = s;
 	return 0;
@@ -323,13 +323,13 @@ static char jpath[PATH_MAX];
 static bool jskip;
 static uint64_t jsize;
 
-static int journal_dir_parser(char *s)
+static int journal_dir_parser(const char *s)
 {
 	snprintf(jpath, sizeof(jpath), "%s", s);
 	return 0;
 }
 
-static int journal_size_parser(char *s)
+static int journal_size_parser(const char *s)
 {
 	if (option_parse_size(s, &jsize) < 0)
 		return -1;
@@ -342,7 +342,7 @@ static int journal_size_parser(char *s)
 	return 0;
 }
 
-static int journal_skip_parser(char *s)
+static int journal_skip_parser(const char *s)
 {
 	jskip = true;
 	return 0;
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 0feffef..60ebbe0 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -224,12 +224,12 @@ int default_format(void);
 int default_remove_object(uint64_t oid);
 int default_get_hash(uint64_t oid, uint32_t epoch, uint8_t *sha1);
 int default_purge_obj(void);
-int for_each_object_in_wd(int (*func)(uint64_t, char *, uint32_t, void *), bool,
-			  void *);
-int for_each_object_in_stale(int (*func)(uint64_t oid, char *path,
+int for_each_object_in_wd(int (*func)(uint64_t, const char *, uint32_t, void *),
+			  bool, void *);
+int for_each_object_in_stale(int (*func)(uint64_t oid, const char *path,
 					 uint32_t epoch, void *arg),
 			     void *arg);
-int for_each_obj_path(int (*func)(char *path));
+int for_each_obj_path(int (*func)(const char *path));
 
 extern struct list_head store_drivers;
 #define add_store_driver(driver)				\
@@ -265,7 +265,7 @@ static inline bool is_aligned_to_pagesize(void *p)
 	return ((uintptr_t)p & (getpagesize() - 1)) == 0;
 }
 
-int create_listen_port(char *bindaddr, int port);
+int create_listen_port(const char *bindaddr, int port);
 int init_unix_domain_socket(const char *dir);
 
 int init_store_driver(bool is_gateway);
@@ -437,12 +437,12 @@ journal_write_store(uint64_t oid, const char *buf, size_t size, off_t, bool);
 int journal_remove_object(uint64_t oid);
 
 /* md.c */
-bool md_add_disk(char *path);
+bool md_add_disk(const char *path);
 uint64_t md_init_space(void);
 const char *md_get_object_path(uint64_t oid);
-int md_handle_eio(char *);
+int md_handle_eio(const char *);
 bool md_exist(uint64_t oid);
-int md_get_stale_path(uint64_t oid, uint32_t epoch, char *path);
+int md_get_stale_path(uint64_t oid, uint32_t epoch, char *path, size_t size);
 uint32_t md_get_info(struct sd_md_info *info);
 int md_plug_disks(char *disks);
 int md_unplug_disks(char *disks);
-- 
1.7.9.5




More information about the sheepdog mailing list