Skip to content

Commit fa47510

Browse files
author
s.hasert
committed
Increased TSM-buffer size to 16 MiB
The TSM-buffer size was increased to 16 MiB. As a consquence of this the TSM buffer has to be allocated on the heap for ltsmc.c and common.c to prevent segmentation faults. Added missing free() Added change to ltsm.spec + corrected changelog Added condition in function crc32file() for setting crc32result Added early exit for empty buffer & checks for empty buffer before free moved freeing of buf Assign buf to NULL for safety + summarized two lines into one Check success of mallocs + assign buf to NULL after free + moved free of buf under loop - `malloc()` now gets checked for success. If they fail we goto cleanup. - `buf` now gets assigned to `NULL` after being freed. - `free()` of `buf` got moved immediately under loop that uses it.
1 parent bfe4541 commit fa47510

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

debian/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
ltsm (0.9.2) unstable; urgency=low
2+
3+
* Increased buffersize to 16 MiB
4+
5+
-- Samuel Hasert <[email protected]> Mon, 15 Sep 2025 11:33:05 +0200
6+
17
ltsm (0.9.1) unstable; urgency=low
28

39
* Finalize remove of FSQ project.

rpm/ltsm.spec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ rm -rf %{buildroot}
6464

6565
%changelog
6666

67+
* Mon Sep 15 2025 Samuel Hasert <[email protected]> 0.9.2
68+
- Increased buffersize to 16 MiB
69+
6770
* Thu Jul 28 2022 Thomas Stibor <[email protected]> 0.9.0-1
6871
- Remove FSQ to keep LTSM as a Lustre TSM copytool project.
6972

src/lib/common.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,20 @@ int crc32file(const char *filename, uint32_t *crc32result)
152152
FILE *file;
153153
size_t cur_read;
154154
uint32_t crc32sum = 0;
155-
unsigned char buf[TSM_BUF_LENGTH] = {0};
155+
unsigned char* buf = malloc(TSM_BUF_LENGTH); // reserve memory on heap because stack too small
156+
if (!buf) {
157+
rc = errno;
158+
CT_ERROR(rc, "malloc");
159+
160+
return rc;
161+
}
156162

157163
file = fopen(filename, "r");
158164
if (file == NULL) {
159165
rc = -errno;
160166
CT_ERROR(rc, "fopen failed on '%s'", filename);
167+
if (buf) free(buf);
168+
buf = NULL;
161169

162170
return rc;
163171
}
@@ -174,17 +182,20 @@ int crc32file(const char *filename, uint32_t *crc32result)
174182

175183
} while (!feof(file));
176184

177-
int rc_minor;
185+
if (buf) free(buf);
186+
buf = NULL;
178187

179-
rc_minor = fclose(file);
188+
int rc_minor = fclose(file);
180189
if (rc_minor) {
181190
rc_minor = -errno;
182191
CT_ERROR(rc_minor, "fclose failed on '%s'", filename);
183192

184193
return rc_minor;
185194
}
186195

187-
*crc32result = crc32sum;
196+
if (!rc) {
197+
*crc32result = crc32sum;
198+
}
188199

189200
return rc;
190201
}

src/lib/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#endif
4747

4848
#ifndef TSM_BUF_LENGTH
49-
#define TSM_BUF_LENGTH 262144 /* 256 KiB. */
49+
#define TSM_BUF_LENGTH 16777216 /* 16 MiB */
5050
#endif
5151

5252
#ifndef MAX_OPTIONS_LENGTH

src/ltsmc.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,11 @@ int main(int argc, char *argv[])
493493
goto cleanup_tsm;
494494
}
495495

496-
char buf[TSM_BUF_LENGTH] = {0};
496+
char* buf = malloc(TSM_BUF_LENGTH);
497+
if (!buf) {
498+
goto cleanup_tsm;
499+
}
500+
497501
size_t size;
498502
do {
499503
size = fread(buf, 1, TSM_BUF_LENGTH, stdin);
@@ -511,6 +515,9 @@ int main(int argc, char *argv[])
511515
}
512516
} while (!feof(stdin));
513517

518+
if (buf) free(buf);
519+
buf = NULL;
520+
514521
rc = tsm_fclose(&session);
515522
if (rc)
516523
CT_ERROR(errno, "tsm_fclose failed");

0 commit comments

Comments
 (0)