Skip to content

Commit

Permalink
- Unbreak ndmpd server on FreeBSD HEAD(12) and FreeBSD Stable(11).
Browse files Browse the repository at this point in the history
  • Loading branch information
araujobsd committed Oct 1, 2017
1 parent 85b78dd commit ffde7d1
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 168 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ TLM_SRCS = tlm/tlm_util.c \
tlm/tlm_info.c \
tlm/tlm_hardlink.c

#LDADD = -lmd -lpthread -lc
LDADD = -lmd -lpthread -lc -lzfs -lzfs_core -lnvpair -lumem -lbsm
LDADD = -lmd -lpthread -lc
MAN=
CFLAGS += -I. -I./include
CFLAGS+= -DEMC_MODEL

PREFIX ?= /usr/local
DSTDIR = ${PREFIX}/sbin
Expand Down
3 changes: 2 additions & 1 deletion include/ndmp.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2009 Sun Microsystems, Inc.
* Copyright 2017 Marcelo Araujo <araujo@FreeBSD.org>.
* All rights reserved.
*
* Use is subject to license terms.
Expand Down Expand Up @@ -1259,7 +1260,7 @@ typedef enum ndmp_connect_reason ndmp_connect_reason;
struct ndmp_notify_connected_request {
ndmp_connect_reason reason;
u_short protocol_version;
const char *text_reason;
char *text_reason;
};
typedef struct ndmp_notify_connected_request ndmp_notify_connected_request;

Expand Down
1 change: 1 addition & 0 deletions include/ndmp.x
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright 1996, 1997 PDC, Network Appliance.
* Copyright 2009 Sun Microsystems, Inc.
* Copyright 2015 Marcelo Araujo <araujo@FreeBSD.org>.
* All rights reserved.
*
* Use is subject to license terms.
Expand Down
4 changes: 1 addition & 3 deletions include/ndmpd.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2009 Sun Microsystems, Inc.
* Copyright 2015 Marcelo Araujo <araujo@FreeBSD.org>.
* Copyright 2017 Marcelo Araujo <araujo@FreeBSD.org>.
* All rights reserved.
*
* Use is subject to license terms.
Expand Down Expand Up @@ -47,7 +47,6 @@
#include <sys/socket.h>
#include <string.h> /* memset */
#include <unistd.h> /* close */
#include <stdio.h>

/* free() */
#include <stdlib.h>
Expand Down Expand Up @@ -319,6 +318,5 @@ int ndmp_run(u_long port, ndmp_con_handler_func_t con_handler_func);
void connection_handler(ndmp_connection_t *connection);
bool_t file_exists(const char * filename);
int startNDMPD(void);
static char * getline_ndmpd(FILE *fp, char *line, int llen);

#endif /* _NDMPD_H_ */
2 changes: 1 addition & 1 deletion include/ndmpd_fhistory.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2009 Sun Microsystems, Inc.
* Copyright 2017 Marcelo Araujo <araujo@FreeBSD.org>.
* All rights reserved.
*
* Use is subject to license terms.
Expand Down Expand Up @@ -60,6 +61,5 @@ int ndmpd_fhnode_v3_cb(lbr_fhlog_call_backs_t *cbp, char *dir, char *file,
struct stat *stp, u_longlong_t off);
int ndmpd_path_restored_v3(lbr_fhlog_call_backs_t *cbp, char *name,
struct stat *st, u_longlong_t ll_idx);
char *get_bk_path_v3(ndmpd_module_params_t *params);

#endif /* _NDMPD_FHISTORY_H */
3 changes: 1 addition & 2 deletions include/ndmpd_prop.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2009 Sun Microsystems, Inc.
* Copyright 2017 Marcelo Araujo <araujo@FreeBSD.org>.
* All rights reserved.
*
* Use is subject to license terms.
Expand Down Expand Up @@ -123,8 +124,6 @@ int ndmpd_load_prop(const char *);
char *ndmpd_get_prop(ndmpd_cfg_id_t id);
char *ndmpd_get_prop_default(ndmpd_cfg_id_t id, char *dflt);
int ndmpd_get_prop_yorn(ndmpd_cfg_id_t id);
void print_prop(void);
void setup(char *line);

#ifdef __cplusplus
}
Expand Down
4 changes: 1 addition & 3 deletions include/ndmpd_tar_v3.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2009 Sun Microsystems, Inc.
* Copyright 2017 Marcelo Araujo <araujo@FreeBSD.org>.
* All rights reserved.
*
* Use is subject to license terms.
Expand Down Expand Up @@ -55,7 +56,6 @@

extern bool_t ndmp_ignore_ctime;
extern bool_t ndmp_include_lmtime;
extern int multiple_dest_restore;

/* Defined */
ndmp_error ndmp_restore_get_params_v3(ndmpd_session_t *session,
Expand All @@ -67,7 +67,5 @@ int ndmp_send_recovery_stat_v3(ndmpd_module_params_t *params,

void setWriteBufDone(tlm_buffers_t *bufs);
void setReadBufDone(tlm_buffers_t *bufs);
char ** setupsels(ndmpd_session_t *session, ndmpd_module_params_t *params,
ndmp_lbr_params_t *nlp, int index);

#endif /* _NDMPD_TAR_V3_ */
12 changes: 4 additions & 8 deletions include/ndmpd_util.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2009 Sun Microsystems, Inc.
* Copyright 2017 Marcelo Araujo <araujo@FreeBSD.org>.
* All rights reserved.
*
* Use is subject to license terms.
Expand Down Expand Up @@ -65,11 +66,6 @@
#define IN_ADDR(x) \
(*(struct in_addr *)&x)

/*
* Mutex to protect Nlp
*/
extern mutex_t nlp_mtx;

/* defined in ndmpd_func */
extern int ndmp_full_restore_path;
extern int ndmp_ver;
Expand Down Expand Up @@ -108,7 +104,7 @@ void ndmp_session_ref(ndmpd_session_t *session);
void ndmp_session_unref(ndmpd_session_t *session);

char *ndmp_new_job_name(char *jname);
int ndmp_get_cur_bk_time(ndmp_lbr_params_t *nlp, time_t *tp);
int ndmp_get_cur_bk_time(ndmp_lbr_params_t *nlp, time_t *tp, char *jname);
long ndmp_buffer_get_size(ndmpd_session_t *session);
void ndmpd_get_file_entry_type(int mode, ndmp_file_type *ftype);
char *ndmp_get_relative_path(char *base, char *fullpath);
Expand All @@ -120,7 +116,7 @@ void ndmp_lbr_cleanup(ndmpd_session_t *session);

bool_t ndmp_valid_v3addr_type(ndmp_addr_type type);
int ndmp_connect_sock_v3(u_long addr, u_short port);
const char **ndmpd_make_exc_list(void);
char **ndmpd_make_exc_list(void);

bool_t fs_is_valid_logvol(char *path);
char *ndmpd_mk_temp(char *buf);
Expand Down Expand Up @@ -149,7 +145,7 @@ void ndmp_copy_addr_v4(ndmp_addr_v4 *dst, ndmp_addr_v4 *src);
int ndmp_lbr_init(ndmpd_session_t *session);
void ndmp_copy_addr_v3(ndmp_addr_v3 *dst, ndmp_addr_v3 *src);

const char *cctime(time_t *t);
char *cctime(time_t *t);

char *ndmp_base64_encode(char *);
char *ndmp_base64_decode(char *);
Expand Down
2 changes: 2 additions & 0 deletions include/tlm_util.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2009 Sun Microsystems, Inc.
* Copyright 2017 Marcelo Araujo <araujo@FreeBSD.org>.
* All rights reserved.
*
* Use is subject to license terms.
Expand Down Expand Up @@ -69,6 +70,7 @@ int cstack_pop(cstack_t *stk, void **data, int *len);
int cstack_top(cstack_t *stk, void **data, int *len);
bool_t match(char *patn, char *str);
int match_ci(char *patn, char *str);
static bool_t parse_match(char line, char *seps);
char *parse(char **line, char *seps);
int oct_atoi(char *p);
char *strupr(char *s);
Expand Down
Empty file modified out/test_tool/ndmpc
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion src/ndmp_xdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ xdr_ndmp_notify_connected_request(XDR *xdrs, ndmp_notify_connected_request *objp
return (FALSE);
if (!xdr_u_short(xdrs, &objp->protocol_version))
return (FALSE);
if (!xdr_string(xdrs, (void *)&objp->text_reason, ~0))
if (!xdr_string(xdrs, &objp->text_reason, ~0))
return (FALSE);
return (TRUE);
}
Expand Down
34 changes: 19 additions & 15 deletions src/ndmpd.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2009 Sun Microsystems, Inc.
* Copyright 2017 Marcelo Araujo <araujo@FreeBSD.org>.
* All rights reserved.
*
* Use is subject to license terms.
Expand Down Expand Up @@ -40,8 +41,6 @@
*/

#include <stdio.h>
#include <signal.h>
#include <assert.h>

/* getopt */
#include <unistd.h>
Expand All @@ -54,10 +53,14 @@
#include <ndmpd_table.h>
#include <ndmpd_prop.h>

#include <signal.h>
#include <assert.h>

/* for print log function */
#include <stdarg.h>

extern void ndmpd_mover_cleanup(ndmpd_session_t *session);

extern ndmp_connection_t *ndmp_create_xdr_connection(void);
extern void ndmp_destroy_xdr_connection(ndmp_connection_t *);
extern void *ndmp_malloc(size_t size);
Expand All @@ -81,12 +84,11 @@ ndmpd_log(int level, const char *fmt,...)
{
va_list arg;
va_start(arg, fmt);

if (PRINT_DEBUG_LOG) {
if (PRINT_DEBUG_LOG){
vfprintf(stderr, fmt, arg);
fprintf(stderr, "\n");
} else {
if (level != LOG_DEBUG) {
}else{
if(level!=LOG_DEBUG){
vfprintf(stderr, fmt, arg);
fprintf(stderr, "\n");
}
Expand Down Expand Up @@ -164,11 +166,11 @@ ndmp_run(u_long port, ndmp_con_handler_func_t con_handler_func)
sin.sin_family = AF_INET;

listenIP = getIPfromNIC(ndmpd_get_prop(NDMP_LISTEN_NIC));
printf("Management on IP: %s\n", listenIP);
if (strcmp(ndmpd_get_prop(NDMP_SERVE_NIC),"") == 0)
printf("Data Transfer on IP: %s\n",getIPfromNIC(ndmpd_get_prop(NDMP_LISTEN_NIC)));
printf("listen on IP: %s\n",listenIP);
if(strcmp(ndmpd_get_prop(NDMP_SERVE_NIC),"")==0)
printf(" Serve on IP: %s\n",getIPfromNIC(ndmpd_get_prop(NDMP_LISTEN_NIC)));
else
printf("Data Transfer on IP: %s\n",getIPfromNIC(ndmpd_get_prop(NDMP_SERVE_NIC)));
printf(" Serve on IP: %s\n",getIPfromNIC(ndmpd_get_prop(NDMP_SERVE_NIC)));

sin.sin_addr.s_addr = inet_addr(listenIP);
sin.sin_port = htons(port);
Expand Down Expand Up @@ -207,9 +209,9 @@ ndmp_run(u_long port, ndmp_con_handler_func_t con_handler_func)
*
* */
childPID = fork();
if (childPID >= 0) // fork was successful
if(childPID >= 0) // fork was successful
{
if (childPID == 0) {
if(childPID == 0) {
close(server_socket);

ndmpd_log(LOG_DEBUG, "connection fd: %d, got socket, start to process", ns);
Expand All @@ -220,7 +222,7 @@ ndmp_run(u_long port, ndmp_con_handler_func_t con_handler_func)
if ((argp = ndmp_malloc(sizeof (ndmpd_worker_arg_t))) != NULL) {
argp->nw_sock = ns;
argp->nw_ipaddr = ipaddr;
/* assign handler function */
/* assign handler function */
argp->nw_con_handler_func = con_handler_func;
ndmpd_worker(argp);
}
Expand Down Expand Up @@ -249,7 +251,7 @@ void
connection_handler(ndmp_connection_t *connection)
{
ndmpd_log(LOG_DEBUG, " - connection_handler: handle the connection START - %d",
connection->conn_sock);
connection->conn_sock);
static int conn_id = 1;
ndmpd_session_t session;
ndmp_notify_connected_request req;
Expand Down Expand Up @@ -290,7 +292,7 @@ connection_handler(ndmp_connection_t *connection)

req.reason = NDMP_CONNECTED;
req.protocol_version = ndmp_ver;
req.text_reason = "";
req.text_reason = (char *)"";

/* Send request to tell the client that we're ready for connection */
if (ndmp_send_request_lock(connection,
Expand Down Expand Up @@ -429,3 +431,5 @@ main(int argc, char *argv[])

return 0;
}


3 changes: 2 additions & 1 deletion src/ndmpd_dtime.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2009 Sun Microsystems, Inc.
* Copyright 2017 Marcelo Araujo <araujo@FreeBSD.org>.
* All rights reserved.
*
* Use is subject to license terms.
Expand Down Expand Up @@ -274,7 +275,7 @@ ddates_pathname(char *buf)
}

/*
* getline_ndmpd
* getline
*
* Get a line from the file and handle the continued lines.
*/
Expand Down
5 changes: 1 addition & 4 deletions src/ndmpd_info.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2009 Sun Microsystems, Inc.
* Copyright 2017 Marcelo Araujo <araujo@FreeBSD.org>.
* All rights reserved.
*
* Use is subject to license terms.
Expand Down Expand Up @@ -245,8 +246,6 @@ ndmpd_config_get_butype_info_v3(ndmp_connection_t *connection, void *body)
NDMP_SETENV(envp, "FILESYSTEM", "");
NDMP_SETENV(envp, "UPDATE", "");
NDMP_SETENV(envp, "HIST", "n");
NDMP_SETENV(envp, "QNAP_EFILE0", "");
NDMP_SETENV(envp, "QNAP_EDIR0", "");
NDMP_SETENV(envp, "FILES", "");
NDMP_SETENV(envp, "SNAPSURE", "NO");
NDMP_SETENV(envp, "LEVEL", "0");
Expand Down Expand Up @@ -571,8 +570,6 @@ ndmpd_config_get_butype_info_v4(ndmp_connection_t *connection, void *body)
NDMP_SETENV(envp, "FILESYSTEM", "");
NDMP_SETENV(envp, "UPDATE", "");
NDMP_SETENV(envp, "HIST", "n");
NDMP_SETENV(envp, "QNAP_EFILE0", "");
NDMP_SETENV(envp, "QNAP_EDIR0", "");
NDMP_SETENV(envp, "FILES", "");
NDMP_SETENV(envp, "SNAPSURE", "NO");
NDMP_SETENV(envp, "LEVEL", "0");
Expand Down
8 changes: 4 additions & 4 deletions src/ndmpd_prop.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2009 Sun Microsystems, Inc.
* Copyright 2017 Marcelo Araujo <araujo@FreeBSD.org>.
* All rights reserved.
*
* Use is subject to license terms.
Expand Down Expand Up @@ -51,7 +52,7 @@
#include "ndmpd.h"

typedef struct ndmpd_cfg_param {
const char *name;
char *name;
char value[64+1];
} ndmpd_cfg_param_t;

Expand All @@ -64,7 +65,6 @@ typedef struct ndmpd_cfg_param {
* 4. serve-ip
*
* */
static
ndmpd_cfg_param_t ndmpd_cfg_table[] =
{
{"listen-nic", ""},
Expand Down Expand Up @@ -106,8 +106,7 @@ void print_prop(){
* config table.
*/
void setup(char *line){
int ki,vi,iskey;
unsigned long idx;
int ki,vi,idx,iskey;
char key[64];
char value[64+1];
ndmpd_cfg_id_t id;
Expand Down Expand Up @@ -176,6 +175,7 @@ char *
ndmpd_get_prop(ndmpd_cfg_id_t id)
{
char *env_val;
int i=0;

if (id < NDMP_MAXALL) {
env_val = ndmpd_cfg_table[id].value;
Expand Down
Loading

0 comments on commit ffde7d1

Please sign in to comment.