Skip to content

Commit

Permalink
added BackupPC::XS::DirOps::refCountAllInodeMax() and bpc_path_refCou…
Browse files Browse the repository at this point in the history
…ntAllInodeMax() to

allow BackupPC_refCountAll to get the lagest inode as the backup tree is traversed.
Also bumped version to 0.57.
  • Loading branch information
craigbarratt committed Dec 2, 2017
1 parent e40a1d4 commit 1575034
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 6 deletions.
17 changes: 17 additions & 0 deletions BackupPC_XS.xs
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,23 @@ refCountAll(path, compress, incr = 1, deltaInfo = NULL)
OUTPUT:
RETVAL

void
refCountAllInodeMax(path, compress, incr = 1, deltaInfo = NULL)
char *path;
int compress;
int incr;
BackupPC::XS::DeltaRefCnt deltaInfo;
PREINIT:
int retVal;
unsigned int inodeMax = 0;
PPCODE:
{
retVal = bpc_path_refCountAllInodeMax(deltaInfo, path, compress, incr, &inodeMax);
EXTEND(SP, 2);
PUSHs(sv_2mortal(newSViv(retVal)));
PUSHs(sv_2mortal(newSViv(inodeMax)));
}

int
lockRangeFd(fd, offset, len, block)
int fd;
Expand Down
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Revision history for Perl extension BackupPC-XS.

0.57: Dec 2, 2017

- added BackupPC::XS::DirOps::refCountAllInodeMax() and bpc_path_refCountAllInodeMax() to allow
BackupPC_refCountAll to get the lagest inode as the backup tree is traversed.

0.56: Jun 11, 2017

- change to Makefile.PL to ensure that parallel builds (make -j N) work with BSD make
Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BackupPC-XS version 0.56
BackupPC-XS version 0.57
========================

BackupPC::XS implements various BackupPC functions in a perl-callable
Expand Down
2 changes: 2 additions & 0 deletions backuppc.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ void bpc_logMsgCBSet(void (*cb)(int errFlag, char *mesg, size_t mesgLen));
int bpc_path_create(char *path);
int bpc_path_remove(bpc_deltaCount_info *deltaInfo, char *path, int compress);
int bpc_path_refCountAll(bpc_deltaCount_info *deltaInfo, char *path, int compress, int incr);
int bpc_path_refCountAllInodeMax(bpc_deltaCount_info *deltaInfo, char *path, int compress, int incr, unsigned int *inodeMax);
int bpc_lockRangeFd(int fd, OFF_T offset, OFF_T len, int block);
int bpc_unlockRangeFd(int fd, OFF_T offset, OFF_T len);
int bpc_lockRangeFile(char *lockFile, OFF_T offset, OFF_T len, int block);
Expand Down Expand Up @@ -329,6 +330,7 @@ void bpc_attrib_dirInit(bpc_attrib_dir *dir, int compressLevel);
void bpc_attrib_dirDestroy(bpc_attrib_dir *dir);
ssize_t bpc_attrib_getEntries(bpc_attrib_dir *dir, char *entries, ssize_t entrySize);
void bpc_attrib_dirRefCount(bpc_deltaCount_info *deltaInfo, bpc_attrib_dir *dir, int incr);
void bpc_attrib_dirRefCountInodeMax(bpc_deltaCount_info *deltaInfo, bpc_attrib_dir *dir, int incr, unsigned int *inodeMax);
void bpc_attrib_attribFilePath(char *path, char *dir, char *attribFileName);
bpc_digest *bpc_attrib_dirDigestGet(bpc_attrib_dir *dir);
uchar *bpc_attrib_buf2file(bpc_attrib_file *file, uchar *buf, uchar *bufEnd, int xattrNumEntries);
Expand Down
16 changes: 15 additions & 1 deletion bpc_attrib.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ void bpc_attrib_dirDestroy(bpc_attrib_dir *dir)
typedef struct {
bpc_deltaCount_info *deltaInfo;
int incr;
unsigned int *inodeMax;
} fileRefCnt_info;

static void bpc_attrib_fileRefCount(bpc_attrib_file *file, fileRefCnt_info *info)
Expand All @@ -406,18 +407,22 @@ static void bpc_attrib_fileRefCount(bpc_attrib_file *file, fileRefCnt_info *info
if ( BPC_LogLevel >= 7 ) bpc_logMsgf("bpc_attrib_fileRefCount: file %s digest %s delta %d\n", file->name, hexStr, info->incr);
bpc_poolRefDeltaUpdate(info->deltaInfo, file->compress, &file->digest, info->incr);
}
if ( info->inodeMax && file->inode > *info->inodeMax ) {
*info->inodeMax = file->inode;
}
}

/*
* call refDeltaUpdate with incr (typically +/-1) for every entry in the directory,
* as well as the dir itself.
*/
void bpc_attrib_dirRefCount(bpc_deltaCount_info *deltaInfo, bpc_attrib_dir *dir, int incr)
void bpc_attrib_dirRefCountInodeMax(bpc_deltaCount_info *deltaInfo, bpc_attrib_dir *dir, int incr, unsigned int *inodeMax)
{
fileRefCnt_info info;

info.deltaInfo = deltaInfo;
info.incr = incr;
info.inodeMax = inodeMax;
bpc_hashtable_iterate(&dir->filesHT, (void*)bpc_attrib_fileRefCount, &info);
if ( dir->digest.len > 0 ) {
char hexStr[BPC_DIGEST_LEN_MAX * 2 + 1];
Expand All @@ -429,6 +434,15 @@ void bpc_attrib_dirRefCount(bpc_deltaCount_info *deltaInfo, bpc_attrib_dir *dir,
}
}

/*
* call refDeltaUpdate with incr (typically +/-1) for every entry in the directory,
* as well as the dir itself.
*/
void bpc_attrib_dirRefCount(bpc_deltaCount_info *deltaInfo, bpc_attrib_dir *dir, int incr)
{
bpc_attrib_dirRefCountInodeMax(deltaInfo, dir, incr, NULL);
}

typedef struct {
char *entries;
ssize_t entryIdx;
Expand Down
15 changes: 12 additions & 3 deletions bpc_dirOps.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ int bpc_path_remove(bpc_deltaCount_info *deltaInfo, char *path, int compress)
* Reference count all the files below the directory path, based on the attrib
* files in and below path.
*/
int bpc_path_refCountAll(bpc_deltaCount_info *deltaInfo, char *path, int compress, int incr)
int bpc_path_refCountAllInodeMax(bpc_deltaCount_info *deltaInfo, char *path, int compress, int incr, unsigned int *inodeMax)
{
char filePath[BPC_MAXPATHLEN];
STRUCT_STAT st;
Expand Down Expand Up @@ -217,7 +217,7 @@ int bpc_path_refCountAll(bpc_deltaCount_info *deltaInfo, char *path, int compres
errorCnt++;
} else {
if ( BPC_LogLevel >= 9 ) bpc_logMsgf("bpc_path_refCountAll: adjusting ref counts from attrib file %s\n", filePath);
bpc_attrib_dirRefCount(deltaInfo, &dir, incr);
bpc_attrib_dirRefCountInodeMax(deltaInfo, &dir, incr, inodeMax);
}
bpc_attrib_dirDestroy(&dir);
}
Expand All @@ -230,13 +230,22 @@ int bpc_path_refCountAll(bpc_deltaCount_info *deltaInfo, char *path, int compres
if ( dirList ) {
for ( dirListP = dirList ; dirListP < dirList + dirListLen ; dirListP += strlen(dirListP) + 1 ) {
snprintf(filePath, sizeof(filePath), "%s/%s", path, dirListP);
errorCnt += bpc_path_refCountAll(deltaInfo, filePath, compress, incr);
errorCnt += bpc_path_refCountAllInodeMax(deltaInfo, filePath, compress, incr, inodeMax);
}
free(dirList);
}
return errorCnt;
}

/*
* Reference count all the files below the directory path, based on the attrib
* files in and below path.
*/
int bpc_path_refCountAll(bpc_deltaCount_info *deltaInfo, char *path, int compress, int incr)
{
return bpc_path_refCountAllInodeMax(deltaInfo, path, compress, incr, NULL);
}

/*
* Add an exclusive lock to the byte range in the given file.
* Blocks until the lock becomes available.
Expand Down
2 changes: 1 addition & 1 deletion lib/BackupPC/XS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ my @FILE_TYPES = qw(
'all' => [ @EXPORT_OK ],
);

our $VERSION = '0.56';
our $VERSION = '0.57';

require XSLoader;
XSLoader::load('BackupPC::XS', $VERSION);
Expand Down

0 comments on commit 1575034

Please sign in to comment.