From 50f611fa7df93b3a1a68fd0fdd1586859a7f4ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20Orozco=20Torrez?= <47061294+vandelvan@users.noreply.github.com> Date: Thu, 8 May 2025 11:00:35 -0600 Subject: [PATCH 01/11] Update: validate_error_messages.py to work using python3 (#516) --- validate_error_messages.py | 50 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/validate_error_messages.py b/validate_error_messages.py index 1c607ef0..6bd39cbc 100755 --- a/validate_error_messages.py +++ b/validate_error_messages.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python3 import os import re @@ -27,37 +27,37 @@ def check_line(path, linenum, x): if re.search(r'/\* ltfsresult', line): return None if re.search(r'[^EWID],$', mid): - print 'Bad output level in message ID at %s:%d' % (path, linenum) - print line.rstrip() + print('Bad output level in message ID at %s:%d' % (path, linenum)) + print(line.rstrip()) return None if re.search(r'ltfsmsg\(', line): if mid[0] == '0': - print 'Leading zero(s) in message ID at %s:%d' % (path, linenum) - print line.rstrip() + print('Leading zero(s) in message ID at %s:%d' % (path, linenum)) + print(line.rstrip()) return None if re.search(r'LTFS_ERR', line): if mid[-1] != 'E': - print 'Output level mismatch at %s:%d' % (path, linenum) - print line.rstrip() + print('Output level mismatch at %s:%d' % (path, linenum)) + print(line.rstrip()) return None elif re.search(r'LTFS_WARN', line): if mid[-1] != 'W': - print 'Output level mismatch at %s:%d' % (path, linenum) - print line.rstrip() + print('Output level mismatch at %s:%d' % (path, linenum)) + print(line.rstrip()) return None elif re.search(r'LTFS_INFO', line): if mid[-1] != 'I': - print 'Output level mismatch at %s:%d' % (path, linenum) - print line.rstrip() + print('Output level mismatch at %s:%d' % (path, linenum)) + print(line.rstrip()) return None elif re.search(r'LTFS_DEBUG', line): if mid[-1] != 'D': - print 'Output level mismatch at %s:%d' % (path, linenum) - print line.rstrip() + print('Output level mismatch at %s:%d' % (path, linenum)) + print(line.rstrip()) return None else: - print 'Unknown output level at %s:%d' % (path, linenum) - print line.rstrip() + print('Unknown output level at %s:%d' % (path, linenum)) + print(line.rstrip()) return None return mid elif re.search(r'ltfsresult\(', line): @@ -79,7 +79,7 @@ def check_line(path, linenum, x): for d, dirs, files in os.walk('src'): for f in files: if re.search(r'\.[ch]$', f) or re.search(r'\.cpp$', f): - with file(os.path.join(d, f), 'r') as fd: + with open(os.path.join(d, f), 'r') as fd: linenum = 1 for line in fd: msgid = check_line(os.path.join(d, f), linenum, line) @@ -101,7 +101,7 @@ def check_line(path, linenum, x): start_id = 0 end_id = 1000000 if re.search(r'\.txt$', f): - with file(os.path.join(d, f), 'r') as fd: + with open(os.path.join(d, f), 'r') as fd: linenum = 1 for line in fd: m = re.search(r'start_id:int\s*{\s*(?P[0-9]+)\s*}', line) @@ -111,8 +111,8 @@ def check_line(path, linenum, x): if m is not None: end_id = int(m.group('val')) if end_id < start_id: - print 'Warning: strange message ID range (%d-%d) in %s' % ( - start_id, end_id, os.path.join(d, f)) + print('Warning: strange message ID range (%d-%d) in %s' % ( + start_id, end_id, os.path.join(d, f))) m = re.search(r'^(?P.*)//', line) if m is not None: @@ -122,8 +122,8 @@ def check_line(path, linenum, x): if m is not None: val = int(m.group('val')) if val < start_id or val > end_id: - print 'Message ID %s out of range (%d-%d) at %s:%d' % ( - m.group('id'), start_id, end_id, os.path.join(d, f), linenum) + print('Message ID %s out of range (%d-%d) at %s:%d' % ( + m.group('id'), start_id, end_id, os.path.join(d, f), linenum)) else: msg_list.add(m.group('id')) linenum += 1 @@ -135,14 +135,14 @@ def check_line(path, linenum, x): msg_unref = msg_unref - msg_ids[module] diff = msg_ids[module] - msg_used if len(diff) > 0: - print "Found %d unused message IDs in message bundle '%s':" % (len(diff), module) + print("Found %d unused message IDs in message bundle '%s':" % (len(diff), module)) diff_list = [i for i in diff] diff_list.sort() for i in diff_list: - print '\t%s' % (i,) + print('\t%s' % (i,)) if len(msg_unref) > 0: - print "Found %d undefined message IDs in the source:" % (len(msg_unref),) + print("Found %d undefined message IDs in the source:" % (len(msg_unref),)) unref_list = [i for i in msg_unref] unref_list.sort() for i in unref_list: - print '\t%s' % (i,) + print('\t%s' % (i,)) From 33807bff5106133b4e4cfb8064a183231baf3932 Mon Sep 17 00:00:00 2001 From: Missael Palacios Date: Thu, 2 Oct 2025 19:18:27 -0400 Subject: [PATCH 02/11] Adding logic for the feasibility check (position check) --- src/libltfs/ltfs.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libltfs/ltfs.c b/src/libltfs/ltfs.c index 5400c578..60162feb 100644 --- a/src/libltfs/ltfs.c +++ b/src/libltfs/ltfs.c @@ -2384,12 +2384,13 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol) struct tape_offset old_selfptr, old_backptr; struct ltfs_timespec modtime_old = { .tv_sec = 0, .tv_nsec = 0 }; bool generation_inc = false; - struct tc_position physical_selfptr; + struct tc_position physical_selfptr, current_position; char *cache_path_save = NULL; bool write_perm = (strcmp(reason, SYNC_WRITE_PERM) == 0); bool update_vollock = false; int volstat = -1, new_volstat = 0; char *bc_print = NULL; + unsigned long long diff; CHECK_ARG_NULL(vol, -LTFS_NULL_ARG); @@ -2506,6 +2507,22 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol) vol->index->backptr = old_backptr; goto out_write_perm; } + + /* Get the tape position from the tape drive by using the SCSI command READPOS*/ + ret = tape_update_position(vol->device, ¤t_position); + if (ret < 0) { + ltfsmsg(LTFS_ERR, 11081E, ret); + } + + /* Prior to writing the index, compare the current location of the head position to the head location + that is kept in the cache of ltfs (physical_selfptr). If they are different return error (-1) */ + ltfsmsg(LTFS_INFO, 11334I, "compare offset", (unsigned long long)physical_selfptr.block, (unsigned long long)current_position.block); + diff = ((unsigned long long)physical_selfptr.block - (unsigned long long)current_position.block); + if (abs(diff)) { + ltfsmsg(LTFS_DEBUG, 16503D, "diff not equal zero", ""); + //return -1; + } + old_selfptr = vol->index->selfptr; vol->index->selfptr.partition = partition; vol->index->selfptr.partition = vol->label->part_num2id[physical_selfptr.partition]; From c89ef5773165a6f9e37903e48b472db045935508 Mon Sep 17 00:00:00 2001 From: Missael Palacios Date: Mon, 6 Oct 2025 16:36:38 -0400 Subject: [PATCH 03/11] Protecting LE agains error caused by SIGSTOP and SIGCONT --- src/libltfs/ltfs.c | 25 +++++++++++++++++++++++++ src/libltfs/ltfs.h | 1 + src/libltfs/tape.c | 16 ++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/libltfs/ltfs.c b/src/libltfs/ltfs.c index 60162feb..35cffac6 100644 --- a/src/libltfs/ltfs.c +++ b/src/libltfs/ltfs.c @@ -207,6 +207,18 @@ bool ltfs_is_interrupted(void) return interrupted; } +bool caught_sigcont = false; +void _ltfs_sigcont(int signal) +{ + ltfsmsg(LTFS_DEBUG, 16503D, "_ltfs_sigcont", ""); + caught_sigcont = true; +} + +bool ltfs_caught_sigcont(void) +{ + return caught_sigcont; +} + /** * This function can be used to enable libltfs signal handler * to kill ltfs, mkltfs, ltfsck cleanly @@ -251,6 +263,15 @@ int ltfs_set_signal_handlers(void) return -LTFS_SIG_HANDLER_ERR; } + ret = signal(SIGCONT, _ltfs_sigcont); + if (ret == SIG_ERR) { + signal(SIGINT, SIG_DFL); + signal(SIGHUP, SIG_DFL); + signal(SIGQUIT, SIG_DFL); + signal(SIGTERM, SIG_DFL); + return -LTFS_SIG_HANDLER_ERR; + } + return 0; } #endif @@ -285,6 +306,10 @@ int ltfs_unset_signal_handlers(void) if (rc == SIG_ERR) ret = -LTFS_SIG_HANDLER_ERR; + rc = signal(SIGCONT, SIG_DFL); + if (rc == SIG_ERR) + ret = -LTFS_SIG_HANDLER_ERR; + return ret; } #endif diff --git a/src/libltfs/ltfs.h b/src/libltfs/ltfs.h index 6e2fdb4a..6fe8891c 100644 --- a/src/libltfs/ltfs.h +++ b/src/libltfs/ltfs.h @@ -586,6 +586,7 @@ int ltfs_fs_init(void); void ltfs_set_log_level(int log_level); void ltfs_set_syslog_level(int syslog_level); bool ltfs_is_interrupted(void); +bool ltfs_caught_sigcont(void); int ltfs_set_signal_handlers(void); int ltfs_unset_signal_handlers(void); int ltfs_finish(); diff --git a/src/libltfs/tape.c b/src/libltfs/tape.c index 4de147a9..ce4ce1c1 100644 --- a/src/libltfs/tape.c +++ b/src/libltfs/tape.c @@ -1187,6 +1187,9 @@ int tape_spacefm(struct device_data *dev, int count) ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool ignore_less, bool ignore_nospc) { ssize_t ret; + struct tc_position current_position; + int ret_for_update_position = 0; + unsigned long long diff = 0; CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); CHECK_ARG_NULL(buf, -LTFS_NULL_ARG); @@ -1241,6 +1244,19 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool count = -LTFS_LESS_SPACE; } + if (ltfs_caught_sigcont()) { + ltfsmsg(LTFS_DEBUG, 16503D, "ltfs_caught_sigcont", "tape_write"); + ret_for_update_position = tape_update_position(dev, ¤t_position); + if (ret_for_update_position) { + // Implement the error handling + } + ltfsmsg(LTFS_INFO, 11334I, "compare offset in tape_write", (unsigned long long)dev->position.block, (unsigned long long)current_position.block); + diff = ((unsigned long long)dev->position.block - (unsigned long long)current_position.block); + if (diff) { + return -LTFS_WRITE_ERROR; + } + } + ltfs_mutex_lock(&dev->append_pos_mutex); dev->append_pos[dev->position.partition] = dev->position.block; ltfs_mutex_unlock(&dev->append_pos_mutex); From 0cc254e9f60dda39dc67d924b28e033066268583 Mon Sep 17 00:00:00 2001 From: Missael Palacios Date: Mon, 6 Oct 2025 17:36:23 -0400 Subject: [PATCH 04/11] Using message 17294I when receiving SIGCONT --- messages/libltfs/root.txt | 1 + src/libltfs/ltfs.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/messages/libltfs/root.txt b/messages/libltfs/root.txt index 32882de3..4c02be58 100644 --- a/messages/libltfs/root.txt +++ b/messages/libltfs/root.txt @@ -834,6 +834,7 @@ v 17290I:string { "Partitioning the medium with the destructive method." } 17291I:string { "Unpartitioning the medium with the destructive method." } 17292I:string { "Current position is (%llu, %llu), Error position is (%llu, %llu)." } + 17294I:string { "Continue signal (%d) received" } // For Debug 19999I:string { "%s %s %d." } diff --git a/src/libltfs/ltfs.c b/src/libltfs/ltfs.c index 35cffac6..5c0a5ae2 100644 --- a/src/libltfs/ltfs.c +++ b/src/libltfs/ltfs.c @@ -210,7 +210,7 @@ bool ltfs_is_interrupted(void) bool caught_sigcont = false; void _ltfs_sigcont(int signal) { - ltfsmsg(LTFS_DEBUG, 16503D, "_ltfs_sigcont", ""); + ltfsmsg(LTFS_INFO, 17294I, signal); caught_sigcont = true; } From b24237b8130cdf5065a3ca6c0cc845fbe7303e9f Mon Sep 17 00:00:00 2001 From: Missael Palacios Date: Mon, 20 Oct 2025 14:15:34 -0400 Subject: [PATCH 05/11] Failing against mismatch, make tape to require validation --- messages/libltfs/root.txt | 1 + src/libltfs/ltfs.c | 10 ++++++---- src/libltfs/tape.c | 7 ++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/messages/libltfs/root.txt b/messages/libltfs/root.txt index 4c02be58..d0242b9b 100644 --- a/messages/libltfs/root.txt +++ b/messages/libltfs/root.txt @@ -834,6 +834,7 @@ v 17290I:string { "Partitioning the medium with the destructive method." } 17291I:string { "Unpartitioning the medium with the destructive method." } 17292I:string { "Current position is (%llu, %llu), Error position is (%llu, %llu)." } + 17293I:string { "Position mismatch. Cached tape position = %llu. Current tape position = %llu." } 17294I:string { "Continue signal (%d) received" } // For Debug 19999I:string { "%s %s %d." } diff --git a/src/libltfs/ltfs.c b/src/libltfs/ltfs.c index 5c0a5ae2..4e166031 100644 --- a/src/libltfs/ltfs.c +++ b/src/libltfs/ltfs.c @@ -2536,16 +2536,18 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol) /* Get the tape position from the tape drive by using the SCSI command READPOS*/ ret = tape_update_position(vol->device, ¤t_position); if (ret < 0) { + /* Return error since the current tape position was unable to be determined, so there could be an undetected position mismatch */ ltfsmsg(LTFS_ERR, 11081E, ret); + return -1; } /* Prior to writing the index, compare the current location of the head position to the head location that is kept in the cache of ltfs (physical_selfptr). If they are different return error (-1) */ - ltfsmsg(LTFS_INFO, 11334I, "compare offset", (unsigned long long)physical_selfptr.block, (unsigned long long)current_position.block); diff = ((unsigned long long)physical_selfptr.block - (unsigned long long)current_position.block); - if (abs(diff)) { - ltfsmsg(LTFS_DEBUG, 16503D, "diff not equal zero", ""); - //return -1; + if (diff) { + /* Position mismatch, diff not equal zero */ + ltfsmsg(LTFS_INFO, 17293I, (unsigned long long)physical_selfptr.block, (unsigned long long)current_position.block); + return -1; } old_selfptr = vol->index->selfptr; diff --git a/src/libltfs/tape.c b/src/libltfs/tape.c index ce4ce1c1..b6d24079 100644 --- a/src/libltfs/tape.c +++ b/src/libltfs/tape.c @@ -1248,11 +1248,16 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool ltfsmsg(LTFS_DEBUG, 16503D, "ltfs_caught_sigcont", "tape_write"); ret_for_update_position = tape_update_position(dev, ¤t_position); if (ret_for_update_position) { - // Implement the error handling + /* Return error since the current tape position was unable to be determined, so there could be an undetected position mismatch */ + ltfsmsg(LTFS_ERR, 11081E, ret); + return -LTFS_WRITE_ERROR; } + ltfsmsg(LTFS_INFO, 11334I, "compare offset in tape_write", (unsigned long long)dev->position.block, (unsigned long long)current_position.block); diff = ((unsigned long long)dev->position.block - (unsigned long long)current_position.block); if (diff) { + /* Position mismatch, diff not equal zero */ + ltfsmsg(LTFS_INFO, 17293I, (unsigned long long)dev->position.block, (unsigned long long)current_position.block); return -LTFS_WRITE_ERROR; } } From 855ae402654d95a52761304ef12872d1f82722c1 Mon Sep 17 00:00:00 2001 From: Missael Palacios Date: Mon, 27 Oct 2025 20:05:38 -0400 Subject: [PATCH 06/11] Removing temporal messages --- src/libltfs/ltfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libltfs/ltfs.c b/src/libltfs/ltfs.c index 5b86571c..a08f67b3 100644 --- a/src/libltfs/ltfs.c +++ b/src/libltfs/ltfs.c @@ -2543,6 +2543,8 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol) /* Prior to writing the index, compare the current location of the head position to the head location that is kept in the cache of ltfs (physical_selfptr). If they are different return error (-1) */ diff = ((unsigned long long)physical_selfptr.block - (unsigned long long)current_position.block); + ltfsmsg(LTFS_INFO, 11334I, "compare offset", (unsigned long long)physical_selfptr.block, (unsigned long long)current_position.block); + ltfsmsg(LTFS_INFO, 11334I, "diff=", diff, ""); if (diff) { /* Position mismatch, diff not equal zero */ ltfsmsg(LTFS_INFO, 17293I, (unsigned long long)physical_selfptr.block, (unsigned long long)current_position.block); From 1b904fffe478414a81dc230343fb43d1dc96e497 Mon Sep 17 00:00:00 2001 From: Missael Palacios Date: Mon, 27 Oct 2025 23:25:09 -0400 Subject: [PATCH 07/11] Removing unneeded messages --- src/libltfs/ltfs.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libltfs/ltfs.c b/src/libltfs/ltfs.c index a08f67b3..5b86571c 100644 --- a/src/libltfs/ltfs.c +++ b/src/libltfs/ltfs.c @@ -2543,8 +2543,6 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol) /* Prior to writing the index, compare the current location of the head position to the head location that is kept in the cache of ltfs (physical_selfptr). If they are different return error (-1) */ diff = ((unsigned long long)physical_selfptr.block - (unsigned long long)current_position.block); - ltfsmsg(LTFS_INFO, 11334I, "compare offset", (unsigned long long)physical_selfptr.block, (unsigned long long)current_position.block); - ltfsmsg(LTFS_INFO, 11334I, "diff=", diff, ""); if (diff) { /* Position mismatch, diff not equal zero */ ltfsmsg(LTFS_INFO, 17293I, (unsigned long long)physical_selfptr.block, (unsigned long long)current_position.block); From 6ffafcdd1ec1ac10d1214d86772231000f775dc4 Mon Sep 17 00:00:00 2001 From: Missael Palacios Date: Mon, 3 Nov 2025 21:32:48 -0500 Subject: [PATCH 08/11] Changing function name and addressing PR comments --- src/libltfs/ltfs.c | 9 +++++++-- src/libltfs/ltfs.h | 1 + src/libltfs/tape.c | 8 ++++++-- src/libltfs/tape.h | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/libltfs/ltfs.c b/src/libltfs/ltfs.c index 5b86571c..67ae81f1 100644 --- a/src/libltfs/ltfs.c +++ b/src/libltfs/ltfs.c @@ -209,7 +209,12 @@ bool caught_sigcont = false; void _ltfs_sigcont(int signal) { ltfsmsg(LTFS_INFO, 17294I, signal); - caught_sigcont = true; + ltfs_sigcont_set(true); +} + +void ltfs_sigcont_set(bool sig_val) +{ + caught_sigcont = sig_val; } bool ltfs_caught_sigcont(void) @@ -2533,7 +2538,7 @@ int ltfs_write_index(char partition, char *reason, struct ltfs_volume *vol) } /* Get the tape position from the tape drive by using the SCSI command READPOS*/ - ret = tape_update_position(vol->device, ¤t_position); + ret = tape_get_position_from_drive(vol->device, ¤t_position); if (ret < 0) { /* Return error since the current tape position was unable to be determined, so there could be an undetected position mismatch */ ltfsmsg(LTFS_ERR, 11081E, ret); diff --git a/src/libltfs/ltfs.h b/src/libltfs/ltfs.h index 5e85a904..2fc19bb6 100644 --- a/src/libltfs/ltfs.h +++ b/src/libltfs/ltfs.h @@ -593,6 +593,7 @@ void ltfs_set_log_level(int log_level); void ltfs_set_syslog_level(int syslog_level); bool ltfs_is_interrupted(void); bool ltfs_caught_sigcont(void); +void ltfs_sigcont_set(bool sig_val); int ltfs_set_signal_handlers(void); int ltfs_unset_signal_handlers(void); int ltfs_finish(); diff --git a/src/libltfs/tape.c b/src/libltfs/tape.c index 15cd97b3..c4c84ac6 100644 --- a/src/libltfs/tape.c +++ b/src/libltfs/tape.c @@ -1105,7 +1105,7 @@ int tape_get_position(struct device_data *dev, struct tc_position *pos) /** * Get current tape position by querying the device. */ -int tape_update_position(struct device_data *dev, struct tc_position *pos) +int tape_get_position_from_drive(struct device_data *dev, struct tc_position *pos) { int ret; @@ -1246,7 +1246,7 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool if (ltfs_caught_sigcont()) { ltfsmsg(LTFS_DEBUG, 16503D, "ltfs_caught_sigcont", "tape_write"); - ret_for_update_position = tape_update_position(dev, ¤t_position); + ret_for_update_position = tape_get_position_from_drive(dev, ¤t_position); if (ret_for_update_position) { /* Return error since the current tape position was unable to be determined, so there could be an undetected position mismatch */ ltfsmsg(LTFS_ERR, 11081E, ret); @@ -1262,6 +1262,10 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool } } + // Unset flag to avoid checking it again if it is not needed + ltfs_sigcont_set(false); + + ltfs_mutex_lock(&dev->append_pos_mutex); dev->append_pos[dev->position.partition] = dev->position.block; ltfs_mutex_unlock(&dev->append_pos_mutex); diff --git a/src/libltfs/tape.h b/src/libltfs/tape.h index 91870105..a94ab95f 100644 --- a/src/libltfs/tape.h +++ b/src/libltfs/tape.h @@ -160,7 +160,7 @@ int tape_force_read_only(struct device_data *dev); int tape_rewind(struct device_data *dev); int tape_get_position(struct device_data *dev, struct tc_position *pos); -int tape_update_position(struct device_data *dev, struct tc_position *pos); +int tape_get_position_from_drive(struct device_data *dev, struct tc_position *pos); int tape_seek(struct device_data *dev, struct tc_position *pos); int tape_seek_eod(struct device_data *dev, tape_partition_t partition); From 148556b7db2d9131bce1e325c153e3475832229e Mon Sep 17 00:00:00 2001 From: Missael Palacios Date: Tue, 4 Nov 2025 01:51:46 -0500 Subject: [PATCH 09/11] Catching SIGCONT correctly --- src/libltfs/ltfs.c | 36 +++++++++++++++++++++++------------- src/libltfs/ltfs.h | 2 ++ src/libltfs/tape.c | 2 -- src/main.c | 4 ++++ 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/libltfs/ltfs.c b/src/libltfs/ltfs.c index 67ae81f1..36369f0f 100644 --- a/src/libltfs/ltfs.c +++ b/src/libltfs/ltfs.c @@ -222,6 +222,29 @@ bool ltfs_caught_sigcont(void) return caught_sigcont; } +int ltfs_extra_signal_handlers(void) +{ + ltfs_sighandler_t ret; + ret = signal(SIGCONT, _ltfs_sigcont); + if (ret == SIG_ERR) { + return -LTFS_SIG_HANDLER_ERR; + } + + return 0; +} + +int ltfs_unset_extra_signal_handler(void) +{ + ltfs_sighandler_t rc; + int ret = 0; + + rc = signal(SIGCONT, SIG_DFL); + if (rc == SIG_ERR) + ret = -LTFS_SIG_HANDLER_ERR; + + return ret; +} + /** * This function can be used to enable libltfs signal handler * to kill ltfs, mkltfs, ltfsck cleanly @@ -266,15 +289,6 @@ int ltfs_set_signal_handlers(void) return -LTFS_SIG_HANDLER_ERR; } - ret = signal(SIGCONT, _ltfs_sigcont); - if (ret == SIG_ERR) { - signal(SIGINT, SIG_DFL); - signal(SIGHUP, SIG_DFL); - signal(SIGQUIT, SIG_DFL); - signal(SIGTERM, SIG_DFL); - return -LTFS_SIG_HANDLER_ERR; - } - return 0; } #endif @@ -309,10 +323,6 @@ int ltfs_unset_signal_handlers(void) if (rc == SIG_ERR) ret = -LTFS_SIG_HANDLER_ERR; - rc = signal(SIGCONT, SIG_DFL); - if (rc == SIG_ERR) - ret = -LTFS_SIG_HANDLER_ERR; - return ret; } #endif diff --git a/src/libltfs/ltfs.h b/src/libltfs/ltfs.h index 2fc19bb6..5a792f55 100644 --- a/src/libltfs/ltfs.h +++ b/src/libltfs/ltfs.h @@ -596,6 +596,8 @@ bool ltfs_caught_sigcont(void); void ltfs_sigcont_set(bool sig_val); int ltfs_set_signal_handlers(void); int ltfs_unset_signal_handlers(void); +int ltfs_extra_signal_handlers(void); +int ltfs_unset_extra_signal_handler(void); int ltfs_finish(); /* Public wrappers for tape_* functions */ diff --git a/src/libltfs/tape.c b/src/libltfs/tape.c index c4c84ac6..51594e54 100644 --- a/src/libltfs/tape.c +++ b/src/libltfs/tape.c @@ -1245,7 +1245,6 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool } if (ltfs_caught_sigcont()) { - ltfsmsg(LTFS_DEBUG, 16503D, "ltfs_caught_sigcont", "tape_write"); ret_for_update_position = tape_get_position_from_drive(dev, ¤t_position); if (ret_for_update_position) { /* Return error since the current tape position was unable to be determined, so there could be an undetected position mismatch */ @@ -1253,7 +1252,6 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool return -LTFS_WRITE_ERROR; } - ltfsmsg(LTFS_INFO, 11334I, "compare offset in tape_write", (unsigned long long)dev->position.block, (unsigned long long)current_position.block); diff = ((unsigned long long)dev->position.block - (unsigned long long)current_position.block); if (diff) { /* Position mismatch, diff not equal zero */ diff --git a/src/main.c b/src/main.c index 9b62b061..533ec70d 100644 --- a/src/main.c +++ b/src/main.c @@ -1241,10 +1241,14 @@ int single_drive_main(struct fuse_args *args, struct ltfs_fuse_data *priv) ltfsmsg(LTFS_INFO, 14111I); ltfsmsg(LTFS_INFO, 14112I); ltfsmsg(LTFS_INFO, 14113I); + /* Set handlers for signals that need to be caught while fuse main is running*/ + ltfs_extra_signal_handlers(); ret = fuse_main(args->argc, args->argv, <fs_ops, priv); if (ret != 0) { ltfsmsg(LTFS_WARN, 14123W, ret); } + /* Unset extra handlers once fuse main exits */ + ltfs_unset_extra_signal_handler(); /* Setup signal handler again to terminate cleanly */ ret = ltfs_set_signal_handlers(); From d29056f26394457aa376a9a6ffb7bd38644e0c9e Mon Sep 17 00:00:00 2001 From: Missael Palacios Date: Tue, 4 Nov 2025 02:00:24 -0500 Subject: [PATCH 10/11] changing variable name --- src/libltfs/tape.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libltfs/tape.c b/src/libltfs/tape.c index 51594e54..9dcb2cda 100644 --- a/src/libltfs/tape.c +++ b/src/libltfs/tape.c @@ -1188,7 +1188,7 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool { ssize_t ret; struct tc_position current_position; - int ret_for_update_position = 0; + int ret_for_current_position = 0; unsigned long long diff = 0; CHECK_ARG_NULL(dev, -LTFS_NULL_ARG); @@ -1245,8 +1245,8 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool } if (ltfs_caught_sigcont()) { - ret_for_update_position = tape_get_position_from_drive(dev, ¤t_position); - if (ret_for_update_position) { + ret_for_current_position = tape_get_position_from_drive(dev, ¤t_position); + if (ret_for_current_position) { /* Return error since the current tape position was unable to be determined, so there could be an undetected position mismatch */ ltfsmsg(LTFS_ERR, 11081E, ret); return -LTFS_WRITE_ERROR; From e509bfe600f11e51c3f090328da0fd433001e8f3 Mon Sep 17 00:00:00 2001 From: Missael Palacios Date: Tue, 4 Nov 2025 15:19:24 -0500 Subject: [PATCH 11/11] Changed unset place --- src/libltfs/tape.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libltfs/tape.c b/src/libltfs/tape.c index 9dcb2cda..1387f078 100644 --- a/src/libltfs/tape.c +++ b/src/libltfs/tape.c @@ -1245,6 +1245,9 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool } if (ltfs_caught_sigcont()) { + // Unset flag to avoid checking it again if it is not needed + ltfs_sigcont_set(false); + ret_for_current_position = tape_get_position_from_drive(dev, ¤t_position); if (ret_for_current_position) { /* Return error since the current tape position was unable to be determined, so there could be an undetected position mismatch */ @@ -1260,10 +1263,6 @@ ssize_t tape_write(struct device_data *dev, const char *buf, size_t count, bool } } - // Unset flag to avoid checking it again if it is not needed - ltfs_sigcont_set(false); - - ltfs_mutex_lock(&dev->append_pos_mutex); dev->append_pos[dev->position.partition] = dev->position.block; ltfs_mutex_unlock(&dev->append_pos_mutex);