Skip to content

Commit

Permalink
Merge branch 'bareos-16.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorz committed Oct 6, 2016
2 parents f1006e0 + 5e8e334 commit a6b6b78
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 76 deletions.
1 change: 0 additions & 1 deletion debian/bareos-director.install.in
Expand Up @@ -13,7 +13,6 @@
@confdir@/bareos-dir.d/fileset/Windows?All?Drives.conf @configtemplatedir@/bareos-dir.d/fileset/
@confdir@/bareos-dir.d/job/backup-bareos-fd.conf @configtemplatedir@/bareos-dir.d/job/
@confdir@/bareos-dir.d/job/BackupCatalog.conf @configtemplatedir@/bareos-dir.d/job/
@confdir@/bareos-dir.d/job/BackupClient1.conf @configtemplatedir@/bareos-dir.d/job/
@confdir@/bareos-dir.d/job/RestoreFiles.conf @configtemplatedir@/bareos-dir.d/job/
@confdir@/bareos-dir.d/jobdefs/DefaultJob.conf @configtemplatedir@/bareos-dir.d/jobdefs/
@confdir@/bareos-dir.d/messages/Daemon.conf @configtemplatedir@/bareos-dir.d/messages/
Expand Down
1 change: 0 additions & 1 deletion platforms/packaging/bareos.spec
Expand Up @@ -912,7 +912,6 @@ echo "This is a meta package to install a full bareos system" > %{buildroot}%{_d
%attr(0640, %{director_daemon_user}, %{daemon_group}) %config(noreplace) "%{_sysconfdir}/bareos/bareos-dir.d/fileset/Windows All Drives.conf"
%attr(0640, %{director_daemon_user}, %{daemon_group}) %config(noreplace) %{_sysconfdir}/bareos/bareos-dir.d/job/backup-bareos-fd.conf
%attr(0640, %{director_daemon_user}, %{daemon_group}) %config(noreplace) %{_sysconfdir}/bareos/bareos-dir.d/job/BackupCatalog.conf
%attr(0640, %{director_daemon_user}, %{daemon_group}) %config(noreplace) %{_sysconfdir}/bareos/bareos-dir.d/job/BackupClient1.conf
%attr(0640, %{director_daemon_user}, %{daemon_group}) %config(noreplace) %{_sysconfdir}/bareos/bareos-dir.d/jobdefs/DefaultJob.conf
%attr(0640, %{director_daemon_user}, %{daemon_group}) %config(noreplace) %{_sysconfdir}/bareos/bareos-dir.d/job/RestoreFiles.conf
%attr(0640, %{director_daemon_user}, %{daemon_group}) %config(noreplace) %{_sysconfdir}/bareos/bareos-dir.d/messages/Daemon.conf
Expand Down
4 changes: 0 additions & 4 deletions src/defaultconfigs/bareos-dir.d/job/BackupClient1.conf

This file was deleted.

6 changes: 4 additions & 2 deletions src/dird/ndmp_fhdb_lmdb.c
Expand Up @@ -492,8 +492,10 @@ void ndmp_fhdb_lmdb_register(struct ndmlog *ixlog)
Mmsg(fhdb_state->lmdb_name, "%s/.fhdb_lmdb.%d", working_directory, nis->jcr->JobId);
result = mdb_env_open(fhdb_state->db_env, fhdb_state->lmdb_name, MDB_NOSUBDIR | MDB_NOLOCK | MDB_NOSYNC, 0600);
if (result) {
Dmsg2(dbglvl, _("Unable create LMDB database %s: %s\n"), fhdb_state->lmdb_name, mdb_strerror(result));
Jmsg2(nis->jcr, M_FATAL, 0, _("Unable create LMDB database %s: %s\n"), fhdb_state->lmdb_name, mdb_strerror(result));
Dmsg2(dbglvl, _("Unable to create LMDB database %s: %s. Check OS ulimit settings or adapt FileHistorySize\n"),
fhdb_state->lmdb_name, mdb_strerror(result));
Jmsg2(nis->jcr, M_FATAL, 0, _("Unable to create LMDB database %s: %s. Check OS ulimit settings or adapt FileHistorySize\n"),
fhdb_state->lmdb_name, mdb_strerror(result));
goto bail_out;
}

Expand Down
16 changes: 10 additions & 6 deletions src/dird/storage.c
Expand Up @@ -543,14 +543,18 @@ static inline void free_vol_list(changer_vol_list_t *vol_list)
{
vol_list_t *vl;

foreach_dlist(vl, vol_list->contents) {
if (vl->VolName) {
free(vl->VolName);
if (vol_list->contents) {
foreach_dlist(vl, vol_list->contents) {
if (vl->VolName) {
free(vl->VolName);
}
}
vol_list->contents->destroy();
delete vol_list->contents;
vol_list->contents = NULL;
} else {
Dmsg0(100, "free_vol_list: vol_list->contents already empty\n");
}
vol_list->contents->destroy();
delete vol_list->contents;
vol_list->contents = NULL;
}

/*
Expand Down
27 changes: 19 additions & 8 deletions src/lib/alist.h
Expand Up @@ -33,25 +33,36 @@
*/
#ifdef HAVE_TYPEOF
#define foreach_alist(var, list) \
for ((var)=(typeof((var)))(list)->first(); (var); (var) = (typeof(var))(list)->next())
for ( (var)=list ? (typeof((var)))(list)->first() : NULL; \
(var); \
(var) = (typeof(var))(list)->next() )

#define foreach_alist_index(inx, var, list) \
for ((inx) = 0; ((var) = (typeof((var)))(list)->get((inx))); (inx)++ )
for ( (inx) = 0; \
list ? ((var) = (typeof((var)))(list)->get((inx))) : NULL; \
(inx)++ )

#define foreach_alist_rindex(inx, var, list) \
for ((inx) = ((list)->size() - 1); ((var) = (typeof((var)))(list)->get((inx))); (inx)--)
for ( list ? (inx) = ((list)->size() - 1) : 0; \
list ? ((var) = (typeof((var)))(list)->get((inx))) : NULL; \
(inx)--)

#else
#define foreach_alist(var, list) \
for ((*((void **)&(var))=(void*)((list)->first())); \
(var); \
(*((void **)&(var))=(void*)((list)->next())))
for ( list ? (*((void **)&(var))=(void*)((list)->first())) : NULL; \
(var); \
(*((void **)&(var))=(void*)((list)->next())) )


#define foreach_alist_index(inx, var, list) \
for ((inx) = 0; ((*((void **)&(var)) = (void*)((list)->get((inx))))); (inx)++)
for ( (inx) = 0; \
list ? ((*((void **)&(var)) = (void*)((list)->get((inx))))) : NULL; \
(inx)++ )

#define foreach_alist_rindex(inx, var, list) \
for ((inx) = ((list)->size() - 1); ((*((void **)&(var)) = (void*)((list)->get((inx))))); (inx)--)
for ( list ? (inx) = ((list)->size() - 1) : 0; \
list ? ((*((void **)&(var)) = (void*)((list)->get((inx))))) : NULL; \
(inx)-- )

#endif

Expand Down
47 changes: 18 additions & 29 deletions src/lib/bsock_tcp.c
Expand Up @@ -426,8 +426,6 @@ bool BSOCK_TCP::send()
{
int32_t pktsiz;
int32_t *hdr;
int32_t written = 0;
int32_t packet_msglen = 0;
bool ok = true;

if (errors) {
Expand All @@ -446,13 +444,23 @@ bool BSOCK_TCP::send()
return false;
}

if (msglen > max_message_len) {
if (!m_suppress_error_msgs) {
Qmsg4(m_jcr, M_ERROR, 0,
_("Socket has insane msglen=%d on call to %s:%s:%d\n"),
msglen, m_who, m_host, m_port);
}
return false;
}

if (m_use_locking) {
P(m_mutex);
}

/*
* Store packet length at head of message -- note, we have reserved an int32_t just before msg,
* So we can store there
* Store packet length at head of message.
* Note: we have reserved an int32_t just before msg,
* so it can be stored there.
*/
hdr = (int32_t *)(msg - (int)header_length);

Expand All @@ -461,36 +469,17 @@ bool BSOCK_TCP::send()
*/
if (msglen <= 0) {
pktsiz = header_length; /* signal, no data */
*hdr = htonl(msglen); /* store signal */
ok = send_packet(hdr, pktsiz);
} else {
/*
* msg might be to long for a single Bareos packet.
* If so, send msg as multiple packages.
* msglen > 0 and msglen <= max_message_len
* message fits into one Bareos packet
*/
while (ok && (written < msglen)) {
if ((msglen - written) > max_message_len) {
/*
* Message is to large for a single Bareos packet.
* Send it via multiple packets.
*/
pktsiz = max_packet_size; /* header + data */
packet_msglen = max_message_len;
} else {
/*
* Remaining message fits into one Bareos packet
*/
pktsiz = header_length + (msglen-written); /* header + data */
packet_msglen = (msglen-written);
}

*hdr = htonl(packet_msglen); /* store length */
ok = send_packet(hdr, pktsiz);
written += packet_msglen;
hdr = (int32_t *)(msg + written - (int)header_length);
}
pktsiz = header_length + msglen; /* header + data */
}

*hdr = htonl(msglen); /* store signal or message length */
ok = send_packet(hdr, pktsiz);

if (m_use_locking) {
V(m_mutex);
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/dlist.h
Expand Up @@ -40,10 +40,10 @@
*/
#ifdef HAVE_TYPEOF
#define foreach_dlist(var, list) \
for((var)=NULL; ((var)=(typeof(var))(list)->next(var)); )
for((var)=NULL; list ? ((var)=(typeof(var))(list)->next(var)) : NULL; )
#else
#define foreach_dlist(var, list) \
for((var)=NULL; (*((void **)&(var))=(void*)((list)->next(var))); )
for((var)=NULL; list ? (*((void **)&(var))=(void*)((list)->next(var))) : NULL; )
#endif

struct dlink {
Expand Down Expand Up @@ -166,12 +166,12 @@ inline int dlist::size() const



inline void * dlist::first() const
inline void *dlist::first() const
{
return head;
}

inline void * dlist::last() const
inline void *dlist::last() const
{
return tail;
}
Expand Down
135 changes: 116 additions & 19 deletions src/lib/unittests/alist_test.c
Expand Up @@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2003-2011 Free Software Foundation Europe e.V.
Copyright (C) 2015 Bareos GmbH & Co. KG
Copyright (C) 2015-2016 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -40,37 +40,134 @@ struct FILESET {
alist mylist;
};

/*
* helper functions
*/

void test_alist(void **state) {
(void) state; /* unused */
FILESET *fileset;
void alist_fill(alist *list, int max)
{
char buf[30];
alist *mlist;
int start = 0;

fileset = (FILESET *)malloc(sizeof(FILESET));
memset(fileset, 0, sizeof(FILESET));
fileset->mylist.init();
if (list) {
start = list->size();
}

/*
* fill list with strings of numbers from 0 to n.
*/
for (int i=0; i<max; i++) {
sprintf(buf, "%d", start+i);
list->append(bstrdup(buf));
}

/*
* verify that max elements have been added
*/
assert_int_equal(list->size(), start + max);
}

for (int i=0; i<20; i++) {
/*
* we expect, that the list is filled with strings of numbers from 0 to n.
*/
void test_foreach_alist(alist *list)
{
char *str = NULL;
char buf[30];
int i=0;

/*
* test all available foreach loops
*/

foreach_alist(str, list) {
sprintf(buf, "%d", i);
assert_string_equal(str, buf);
i++;
}

foreach_alist_index(i, str, list) {
sprintf(buf, "%d", i);
assert_string_equal(str, buf);
}

foreach_alist_rindex(i, str, list) {
sprintf(buf, "%d", i);
fileset->mylist.append(bstrdup(buf));
assert_string_equal(str, buf);
}
}

/*
* Tests
*/

void test_alist_init_destroy()
{
FILESET *fileset;
fileset = (FILESET *)malloc(sizeof(FILESET));
memset(fileset, 0, sizeof(FILESET));
fileset->mylist.init();

alist_fill(&(fileset->mylist), 20);
for (int i=0; i< fileset->mylist.size(); i++) {
assert_int_equal(i, atoi((char *)fileset->mylist[i]));
}
fileset->mylist.destroy();
free(fileset);
}

mlist = New(alist(10));

for (int i=0; i<20; i++) {
sprintf(buf, "%d", i);
mlist->append(bstrdup(buf));
}
for (int i=0; i< mlist->size(); i++) {
assert_int_equal(i, atoi((char *)fileset->mylist[i]));
}
delete mlist;

void test_alist_dynamic() {
alist *list=NULL;
char *buf;

// NULL->size() will segfault
//assert_int_equal(list->size(), 0);

// does foreach work for NULL?
test_foreach_alist(list);

// create empty list, which is prepared for a number of entires
list = New(alist(10));
assert_int_equal(list->size(), 0);

// does foreach work for empty lists?
test_foreach_alist(list);

// fill the list
alist_fill(list, 20);
test_foreach_alist(list);

// verify and remove the latest entries
assert_int_equal(list->size(), 20);
buf = (char *)list->pop();
assert_string_equal(buf, "19");
free(buf);

assert_int_equal(list->size(), 19);
buf = (char *)list->pop();
assert_string_equal(buf, "18");
free(buf);

// added more entires
alist_fill(list, 20);
test_foreach_alist(list);

assert_int_equal(list->size(), 38);

delete(list);
}


/*
* main entry point
*/
void test_alist(void **state) {
(void) state; /* unused */

test_alist_init_destroy();
test_alist_dynamic();

sm_dump(false);
}

0 comments on commit a6b6b78

Please sign in to comment.