Skip to content

Commit

Permalink
Make NDMP ImageStream buffer dynamically allocated size.
Browse files Browse the repository at this point in the history
New design that actually works.
  • Loading branch information
Marco van Wieringen committed Nov 16, 2015
1 parent 3a09212 commit c657aeb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
15 changes: 14 additions & 1 deletion src/ndmp/ndma_image_stream.c
Expand Up @@ -66,13 +66,22 @@ int
ndmis_reinit_remote (struct ndm_session *sess)
{
struct ndm_image_stream *is = sess->plumb.image_stream;
struct ndm_tape_agent * ta = sess->tape_acb;

NDMOS_MACRO_ZEROFILL (&is->remote);

ndmchan_initialize (&is->remote.listen_chan, "image-stream-listen");
ndmchan_initialize (&is->remote.sanity_chan, "image-stream-sanity");
ndmchan_initialize (&is->chan, "image-stream");
ndmchan_setbuf (&is->chan, is->buf, sizeof is->buf);
if (!is->buf) {
is->buflen = ta->mover_state.record_size;
is->buf = NDMOS_API_MALLOC (is->buflen);
if (!is->buf) {
return -1;
}
NDMOS_MACRO_ZEROFILL_SIZE (is->buf, is->buflen);
}
ndmchan_setbuf (&is->chan, is->buf, is->buflen);

return 0;
}
Expand Down Expand Up @@ -123,11 +132,15 @@ ndmis_destroy (struct ndm_session *sess)
return 0;
}

if (sess->plumb.image_stream->buf) {
NDMOS_API_FREE (sess->plumb.image_stream->buf);
}
NDMOS_API_FREE (sess->plumb.image_stream);
sess->plumb.image_stream = NULL;

return 0;
}

/* Belay -- Cancel partially issued activation/start */
int
ndmis_belay (struct ndm_session *sess)
Expand Down
7 changes: 2 additions & 5 deletions src/ndmp/ndmagents.h
Expand Up @@ -932,10 +932,6 @@ extern int ndmra_destroy (struct ndm_session *sess);
****************************************************************
*/

#ifndef NDM_N_IMAGE_STREAM_BUF
#define NDM_N_IMAGE_STREAM_BUF (100*1024)
#endif

enum ndmis_connect_status {
NDMIS_CONN_IDLE = 0,
NDMIS_CONN_LISTEN,
Expand Down Expand Up @@ -975,7 +971,8 @@ struct ndm_image_stream {
/* transfer stuff */
int transfer_mode;
struct ndmchan chan;
char buf[NDM_N_IMAGE_STREAM_BUF];
char * buf;
int buflen;
};

extern int ndmis_initialize (struct ndm_session *sess);
Expand Down
8 changes: 7 additions & 1 deletion src/ndmp/ndmos.h
Expand Up @@ -203,6 +203,8 @@
* NDMOS_MACRO_NEWN -- allocate a vector of data structs
* NDMOS_MACRO_ZEROFILL -- zero-fill data structure, wrapper
* around NDMOS_API_BZERO()
* NDMOS_MACRO_ZEROFILL_SIZE -- zero-fill data structure, wrapper
* around NDMOS_API_BZERO()
* NDMOS_MACRO_SRAND -- wrapper around srand(3), for MD5
* NDMOS_MACRO_RAND -- wrapper around rand(3), for MD5
* NDMOS_MACRO_OK_TAPE_REC_LEN -- Uses NDMOS_CONST_TAPE_REC_MIN/MAX
Expand Down Expand Up @@ -318,7 +320,7 @@
#endif /* !NDMOS_CONST_TAPE_REC_MIN */

#ifndef NDMOS_CONST_TAPE_REC_MAX
#define NDMOS_CONST_TAPE_REC_MAX (256*1024)
#define NDMOS_CONST_TAPE_REC_MAX (1024*1024)
#endif /* !NDMOS_CONST_TAPE_REC_MAX */

#ifndef NDMOS_CONST_PATH_MAX
Expand Down Expand Up @@ -420,6 +422,10 @@ extern char *ndml_strend(char *s); /* ndml_util.c */
#define NDMOS_MACRO_ZEROFILL(P) NDMOS_API_BZERO(P,sizeof *(P))
#endif /* !NDMOS_MACRO_ZEROFILL */

#ifndef NDMOS_MACRO_ZEROFILL_SIZE
#define NDMOS_MACRO_ZEROFILL_SIZE(P, N) NDMOS_API_BZERO(P, N)
#endif /* !NDMOS_MACRO_ZEROFILL_SIZE */

#ifndef NDMOS_MACRO_SRAND
#define NDMOS_MACRO_SRAND() srand(time(0))
#endif /* !NDMOS_MACRO_SRAND */
Expand Down

0 comments on commit c657aeb

Please sign in to comment.