From ee826b9618d3aa61127b3046907eca058f74e14c Mon Sep 17 00:00:00 2001
From: Tim Wickberg <tim@schedmd.com>
Date: Wed, 23 Mar 2016 14:31:22 -0400
Subject: [PATCH] Send file_size across as part of the RPC, will be needed for
 mmap.

Remove unused struct and macro from file_bcast.h.

Free file_bcast_info_t to prevent leak.
---
 src/bcast/file_bcast.c           | 8 +-------
 src/bcast/file_bcast.h           | 1 +
 src/common/slurm_protocol_defs.h | 1 +
 src/common/slurm_protocol_pack.c | 2 ++
 src/slurmd/slurmd/req.c          | 4 ++--
 5 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/bcast/file_bcast.c b/src/bcast/file_bcast.c
index 89f0147fe69..d610d407032 100644
--- a/src/bcast/file_bcast.c
+++ b/src/bcast/file_bcast.c
@@ -77,15 +77,8 @@
 
 #include "file_bcast.h"
 
-#define MAX_RETRIES     10
 #define MAX_THREADS      8	/* These can be huge messages, so
 				 * only run MAX_THREADS at one time */
-typedef struct thd {
-	pthread_t thread;	/* thread ID */
-	slurm_msg_t msg;	/* message to send */
-	int rc;			/* highest return codes from RPC */
-	char *nodelist;
-} thd_t;
 
 int block_len;				/* block size */
 int fd;					/* source file descriptor */
@@ -394,6 +387,7 @@ static int _bcast_file(struct bcast_parameters *params)
 	bcast_msg.uid		= f_stat.st_uid;
 	bcast_msg.user_name	= uid_to_string(f_stat.st_uid);
 	bcast_msg.gid		= f_stat.st_gid;
+	bcast_msg.file_size	= f_stat.st_size;
 	bcast_msg.cred          = sbcast_cred->sbcast_cred;
 
 	if (params->preserve) {
diff --git a/src/bcast/file_bcast.h b/src/bcast/file_bcast.h
index 1d47ae9d1fc..822a4219e65 100644
--- a/src/bcast/file_bcast.h
+++ b/src/bcast/file_bcast.h
@@ -66,6 +66,7 @@ typedef struct file_bcast_info {
 	time_t last_update;	/* transfer last block received */
 	int received_blocks;	/* number of blocks received */
 	int max_blocks;		/* highest block number (when known) */
+	void *data;		/* mmap of file data */
 } file_bcast_info_t;
 
 extern int bcast_file(struct bcast_parameters *params);
diff --git a/src/common/slurm_protocol_defs.h b/src/common/slurm_protocol_defs.h
index b743e4da481..7241dd8be8a 100644
--- a/src/common/slurm_protocol_defs.h
+++ b/src/common/slurm_protocol_defs.h
@@ -1084,6 +1084,7 @@ typedef struct file_bcast_msg {
 	uint32_t block_offset;	/* offset for this data block */
 	uint32_t uncomp_len;	/* uncompressed length of this data block */
 	char *block;		/* data for this block */
+	uint64_t file_size;	/* file size */
 } file_bcast_msg_t;
 
 typedef struct multi_core_data {
diff --git a/src/common/slurm_protocol_pack.c b/src/common/slurm_protocol_pack.c
index 1b5b8ad7809..a98dfdb28b0 100644
--- a/src/common/slurm_protocol_pack.c
+++ b/src/common/slurm_protocol_pack.c
@@ -13487,6 +13487,7 @@ static void _pack_file_bcast(file_bcast_msg_t * msg , Buf buffer,
 		pack32 ( msg->block_len, buffer );
 		pack32(msg->uncomp_len, buffer);
 		pack32(msg->block_offset, buffer);
+		pack64(msg->file_size, buffer);
 		packmem ( msg->block, msg->block_len, buffer );
 		pack_sbcast_cred( msg->cred, buffer );
 	} else if (protocol_version >= SLURM_MIN_PROTOCOL_VERSION) {
@@ -13538,6 +13539,7 @@ static int _unpack_file_bcast(file_bcast_msg_t ** msg_ptr , Buf buffer,
 		safe_unpack32 ( & msg->block_len, buffer );
 		safe_unpack32(&msg->uncomp_len, buffer);
 		safe_unpack32(&msg->block_offset, buffer);
+		safe_unpack64(&msg->file_size, buffer);
 		safe_unpackmem_xmalloc ( & msg->block, &uint32_tmp , buffer ) ;
 		if ( uint32_tmp != msg->block_len )
 			goto unpack_error;
diff --git a/src/slurmd/slurmd/req.c b/src/slurmd/slurmd/req.c
index a17bb05d740..9fb13822eb1 100644
--- a/src/slurmd/slurmd/req.c
+++ b/src/slurmd/slurmd/req.c
@@ -3506,10 +3506,10 @@ static void _free_file_bcast_info_t(file_bcast_info_t *f)
 	xfree(f->fname);
 	if (f->fd)
 		close(f->fd);
+	xfree(f);
 }
 
-static int
-_rpc_file_bcast(slurm_msg_t *msg)
+static int _rpc_file_bcast(slurm_msg_t *msg)
 {
 	int rc, offset,inx;
 	file_bcast_msg_t *req = msg->data;
-- 
GitLab