Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/libltfs/arch/filename_handling.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** OO_Copyright_BEGIN
**
**
** Copyright 2010, 2020 IBM Corp. All rights reserved.
** Copyright 2010, 2025 IBM Corp. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -130,6 +130,7 @@ void update_platform_safe_name(struct dentry* dentry, bool handle_invalid_char,
}
}
#else
// Checkup not needed here, memory error handling happens after function calls.
dentry->platform_safe_name = strdup(dentry->name.name);
#endif
}
Expand Down Expand Up @@ -242,6 +243,10 @@ char * _generate_target_file_name(const char *prefix, const char *extension, int
ret = asprintf(&target, "%s.%s", prefix, extension);
else {
target = strdup(prefix);
if (!target) {
ltfsmsg(LTFS_ERR, 10001E, "_generate_target_file_name: target assign");
ret = -1;
}
ret = target ? strlen(target) : -1;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/libltfs/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** OO_Copyright_BEGIN
**
**
** Copyright 2010, 2020 IBM Corp. All rights reserved.
** Copyright 2010, 2025 IBM Corp. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -89,6 +89,7 @@ static char* generate_hash_key_name(const char *src_str, int *rc)
} else
free(uchar_name);
#else
// Chek not needed here for strdup because the error is handled where the function is called
key_name = strdup(src_str);
*rc = 0;
#endif
Expand Down
32 changes: 30 additions & 2 deletions src/libltfs/index_criteria.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** OO_Copyright_BEGIN
**
**
** Copyright 2010, 2020 IBM Corp. All rights reserved.
** Copyright 2010, 2025 IBM Corp. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -288,6 +288,29 @@ int index_criteria_parse_name(const char *criteria, size_t len, struct index_cri
/* Assign rules to the glob_patterns[] array */
rule = rule+5;
for (delim = rule; *delim; delim++) {
bool doDelimAssign = false;
bool doRuleAdd = false;
if (*delim == ':') {
doDelimAssign = true;
doRuleAdd = true;
}
else if (*delim == '/') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the convention. You must not break a line before else.

It looks there are multiple points that is same style. Please correct all of them.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will check them.

doDelimAssign = true;
}
else if (! (*(delim+1) == '\0')) {
continue;
}
if (doDelimAssign) *delim = '\0';
rule_ptr->percent_encode = fs_is_percent_encode_required(rule);
rule_ptr->name = strdup(rule);
if (! rule_ptr->name) {
ltfsmsg(LTFS_ERR, 10001E, "index_criteria_parse_name: rule assign");
free(rule_ptr->name);
return -EDEV_NO_MEMORY;
}
rule_ptr++;
if (doRuleAdd) rule = delim+1;
/*
if (*delim == ':') {
*delim = '\0';
rule_ptr->percent_encode = fs_is_percent_encode_required(rule);
Expand All @@ -303,12 +326,17 @@ int index_criteria_parse_name(const char *criteria, size_t len, struct index_cri
rule_ptr->percent_encode = fs_is_percent_encode_required(rule);
rule_ptr->name = strdup(rule);
rule_ptr++;
}
}*/
}

if (ic->glob_patterns == rule_ptr) {
rule_ptr->percent_encode = fs_is_percent_encode_required(rule);
rule_ptr->name = strdup(rule);
if (! rule_ptr->name) {
ltfsmsg(LTFS_ERR, 10001E, "index_criteria_parse_name: glob_patterns assign");
free(rule_ptr->name);
return -EDEV_NO_MEMORY;
}
}

/* Validate rules */
Expand Down
14 changes: 4 additions & 10 deletions src/libltfs/ltfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1658,8 +1658,7 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec
(unsigned long long)vol->dp_coh.volume_change_ref,
(unsigned long long)volume_change_ref);

/* Index of IP could be corrupted. So set skip flag to true */
ret = _ltfs_search_index_wp(recover_symlink, true, &seekpos, vol);
ret = _ltfs_search_index_wp(recover_symlink, false, &seekpos, vol);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this line is changed?

It looks you ruined the fix made before.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks a change from somewhere else got into the PR, fixing it, thanks for the catch.

if (ret < 0)
goto out_unlock;

Expand All @@ -1669,7 +1668,7 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec
seekpos.block = vol->dp_coh.set_id;
}
} else {
if (vol->ip_coh.count > vol->dp_coh.count && vollock != PWE_MAM_DP && vollock != PWE_MAM) {
if (vollock != PWE_MAM_DP && vollock != PWE_MAM) {
/*
* The index on IP is newer but MAM shows write perm doesn't happen in DP.
* LTFS already have written an index on DP when it is writing an index on IP,
Expand All @@ -1688,13 +1687,8 @@ int ltfs_mount(bool force_full, bool deep_recovery, bool recover_extra, bool rec
(unsigned long long)vol->dp_coh.volume_change_ref,
(unsigned long long)volume_change_ref);

if (vollock == PWE_MAM_BOTH) {
/* Index of IP could be corrupted (because of double write perm). So set skip flag to true */
ret = _ltfs_search_index_wp(recover_symlink, true, &seekpos, vol);
} else {
/* Index of DP could be corrupted. So set skip flag to false */
ret = _ltfs_search_index_wp(recover_symlink, false, &seekpos, vol);
}
/* Index of IP could be corrupted. So set skip flag */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this part is changed?

It looks you ruined the fix made before.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks a change from somewhere else got into the PR, fixing it, thanks for the catch.
@piste-jp Can you also respond my other comments? Thanks, appreciate it.

ret = _ltfs_search_index_wp(recover_symlink, true, &seekpos, vol);
if (ret < 0)
goto out_unlock;

Expand Down
7 changes: 6 additions & 1 deletion src/libltfs/ltfs_fsops.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** OO_Copyright_BEGIN
**
**
** Copyright 2010, 2021 IBM Corp. All rights reserved.
** Copyright 2010, 2025 IBM Corp. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -1912,7 +1912,12 @@ int ltfs_fsops_symlink_path(const char* to, const char* from, ltfs_file_id *id,

id->uid = d->uid;
id->ino = d->ino;
// TODO: Check if the return error is needed or can be skipped.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid adding technical debt hehe, did you just forget to erase this TODO? Or you did not manage to check it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use C++ style command only for comment out.
Use C style comment here /* */ if this comment is really needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do the testing so I can completely remove them, thanks.

d->target.name = strdup(to);
if (! d->target.name) {
ltfsmsg(LTFS_ERR, 10001E, "ltfs_fsops_symlink_path: d target name");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to remove the node created by tfs_fsops_create() in line 1909 at least.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @piste-jp using the following code is enough to remove the node, or do I need to do something else? Thanks

ret2 = ltfs_fsops_close(d, true, true, use_iosche, vol);
if ( ret==0 && ret2<0 ) {
	ret = ret2;
}

return -LTFS_NO_MEMORY;
}
d->target.percent_encode = fs_is_percent_encode_required(to);
d->isslink = true;

Expand Down
6 changes: 5 additions & 1 deletion src/libltfs/ltfs_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** OO_Copyright_BEGIN
**
**
** Copyright 2010, 2020 IBM Corp. All rights reserved.
** Copyright 2010, 2025 IBM Corp. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -1313,6 +1313,10 @@ int ltfs_split_symlink( struct ltfs_volume *vol )
}
ret = ltfs_fsops_close( workd, true, true, use_iosche, vol);
path=strdup(lfdir);
if (! path) {
ltfsmsg(LTFS_ERR, 10001E, "ltfs_split_symlink: path assign");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to remove the node created by tfs_fsops_create() in line 1303 at least.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @piste-jp the node is closed just above those lines, in 1314, is something else needed? Thanks a lot

return -LTFS_NO_MEMORY;
}

/* loop for conflicted files */
for( i=0; i<(vol->index->symerr_count); i++ ){
Expand Down
7 changes: 6 additions & 1 deletion src/libltfs/ltfslogging.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** OO_Copyright_BEGIN
**
**
** Copyright 2010, 2020 IBM Corp. All rights reserved.
** Copyright 2010, 2025 IBM Corp. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -489,6 +489,11 @@ int ltfsmsg_internal(bool print_id, int level, char **msg_out, const char *_id,
vsprintf(msg_buf, output_buf, argp);
va_end(argp);
*msg_out = strdup(msg_buf);
// TODO: Check if the return -1 is needed, or the program can just continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before, please do not add more technical debt, I cannot approve a PR that has not been properly tested 😅

if (!(*msg_out)) {
ltfsmsg(LTFS_ERR, 10001E, "ltfsmsg_internal: msg_out assign");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a terrible idea to use ltfsmsg within this function because this function is used from ltfsmsg.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @piste-jp your insight would be really helpful here, it is crucial to stop the process and return an error in this section (For example using the goto internal_error) or just printing a message using the fprintf or syslog functions? Thanks

return -1;
}
}

#ifdef ENABLE_SNMP
Expand Down
6 changes: 5 additions & 1 deletion src/libltfs/ltfssnmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** OO_Copyright_BEGIN
**
**
** Copyright 2010, 2020 IBM Corp. All rights reserved.
** Copyright 2010, 2025 IBM Corp. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -122,6 +122,10 @@ int read_trap_def_file(char *deffile)
return -LTFS_NO_MEMORY;
}
entry->id = strdup(tok);
if (!entry->id) {
ltfsmsg(LTFS_ERR, 10001E, "read_trap_def_file: entry id assign");
return -LTFS_NO_MEMORY;
}
TAILQ_INSERT_TAIL(&trap_entries, entry, list);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/libltfs/pathname.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** OO_Copyright_BEGIN
**
**
** Copyright 2010, 2020 IBM Corp. All rights reserved.
** Copyright 2010, 2025 IBM Corp. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -953,8 +953,10 @@ int _pathname_utf8_to_system_icu(const char *src, char **dest)
syslocale = ucnv_getDefaultName();
if (! strcmp(syslocale, "UTF-8")) {
*dest = strdup(src);
if (! *dest)
if (! (*dest)) {
ltfsmsg(LTFS_ERR, 10001E, "_pathname_utf8_to_system_icu: dest assign");
return -LTFS_NO_MEMORY;
}
return 0;
}

Expand Down
8 changes: 6 additions & 2 deletions src/libltfs/tape.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** OO_Copyright_BEGIN
**
**
** Copyright 2010, 2020 IBM Corp. All rights reserved.
** Copyright 2010, 2025 IBM Corp. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -1895,6 +1895,10 @@ int tape_get_media_pool_info(struct ltfs_volume *vol, char **media_name, char **
name = strndup(vol->t_attr->media_pool, add_start);
}
info = strdup(&(vol->t_attr->media_pool[add_start+1]));
if (!info) {
ltfsmsg(LTFS_ERR, 10001E, __FILE__);
return -LTFS_NO_MEMORY;
}
len = strlen(info);
info[len-1] = '\0';
}
Expand Down Expand Up @@ -3508,7 +3512,7 @@ int read_tape_attribute(struct ltfs_volume *vol, char **val, const char *name)
*val = strdup(vol->t_attr->media_pool);
}

if (!*val) {
if (!(*val)) {
ltfsmsg(LTFS_ERR, 10001E, "read_tape_attribute: *val");
return -LTFS_UNEXPECTED_VALUE;
}
Expand Down
6 changes: 5 additions & 1 deletion src/libltfs/xml_reader_libltfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** OO_Copyright_BEGIN
**
**
** Copyright 2010, 2020 IBM Corp. All rights reserved.
** Copyright 2010, 2025 IBM Corp. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -154,6 +154,10 @@ static int decode_entry_name(char **new_name, const char *name)
tmp_name[j] = '\0';

*new_name = strdup(tmp_name);
if (! (*new_name)) {
ltfsmsg(LTFS_ERR, 10001E, "decode_entry_name: new name assign");
return -LTFS_NO_MEMORY;
}
free(tmp_name);

return 0;
Expand Down
6 changes: 5 additions & 1 deletion src/libltfs/xml_writer_libltfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** OO_Copyright_BEGIN
**
**
** Copyright 2010, 2020 IBM Corp. All rights reserved.
** Copyright 2010, 2025 IBM Corp. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -131,6 +131,10 @@ static int encode_entry_name(char **new_name, const char *name)
tmp_name[j] = '\0';

*new_name = strdup(tmp_name);
if (! (*new_name)) {
ltfsmsg(LTFS_ERR, 10001E, "encode_entry_name: new name assign");
return -LTFS_NO_MEMORY;
}
free(tmp_name);

return 0;
Expand Down
10 changes: 9 additions & 1 deletion src/tape_drivers/freebsd/cam/cam_cmn.c
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you really test this code? This code is only compiled under FreeBSD.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on it.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** OS_Copyright_BEGIN
**
**
** Copyright 2010, 2018 IBM Corp. All rights reserved.
** Copyright 2010, 2025 IBM Corp. All rights reserved.
** Copyright (c) 2013-2018 Spectra Logic Corporation. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -189,6 +189,10 @@ int camtape_ioctlrc2err(void *device, int fd, struct scsi_sense_data *sense_data

if (msg) {
*msg = strdup("No Sense Information");
if (! (*msg)) {
ltfsmsg(LTFS_ERR, 10001E, "camtape_ioctlrc2err: msg assign");
// TODO: Check if error return is needed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before

}
}
rc = -EDEV_NO_SENSE;
} else {
Expand Down Expand Up @@ -217,6 +221,10 @@ int camtape_ioctlrc2err(void *device, int fd, struct scsi_sense_data *sense_data
ltfsmsg(LTFS_INFO, 31212I, rc_sense);
if (msg)
*msg = strdup("Cannot get sense information");
if (! (*msg)) {
ltfsmsg(LTFS_ERR, 10001E, "camtape_ioctlrc2err: msg assign");
// TODO: Check if error return is needed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before

}

rc = -EDEV_CANNOT_GET_SENSE;
}
Expand Down
15 changes: 13 additions & 2 deletions src/tape_drivers/freebsd/cam/cam_cmn.h
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you really test this code? This code is only compiled under FreeBSD.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on it.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** OS_Copyright_BEGIN
**
**
** Copyright 2010, 2018 IBM Corp. All rights reserved.
** Copyright 2010, 2025 IBM Corp. All rights reserved.
** Copyright (c) 2013-2018 Spectra Logic Corporation. All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -515,6 +515,10 @@ static inline int _sense2errcode(uint32_t sense, struct error_table *table, char
rc = table[i].err_code;
if (msg)
*msg = strdup(table[i].msg);
if (! (*msg)) {
ltfsmsg(LTFS_ERR, 10001E, "_sense2errcode: msg assign");
// TODO: Check if error return is needed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before

}
break;
}
i++;
Expand All @@ -524,7 +528,10 @@ static inline int _sense2errcode(uint32_t sense, struct error_table *table, char
rc = DEVICE_GOOD;
else if (table[i].sense == 0xFFFFFF && table[i].err_code == rc && msg)
*msg = strdup(table[i].msg);

if (! (*msg)) {
ltfsmsg(LTFS_ERR, 10001E, "_sense2errcode: msg assign");
// TODO: Check if error return is needed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before

}
return rc;
}

Expand All @@ -545,6 +552,10 @@ static inline int camtape_send_ccb(struct camtape_data *softc, union ccb *ccb, c

snprintf(tmpstr, sizeof(tmpstr), "cam_send_ccb() failed: %s", strerror(errno));
*msg = strdup(tmpstr);
if (! (*msg)) {
ltfsmsg(LTFS_ERR, 10001E, "camtape_send_ccb: msg assign");
// TODO: Check if error return is needed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before

}
rc = -errno;
} else
rc = camtape_ccb2rc(softc, ccb);
Expand Down
Loading
Loading