Skip to content

Windows support #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: v2.4-stable
Choose a base branch
from

Conversation

Piloalucard
Copy link
Member

@Piloalucard Piloalucard commented Apr 18, 2025

Summary of changes

This pull request includes following changes or fixes.

  • Compatible code with Microsoft Visual C++ Compiler
  • Support of Windows Server 2022
  • Support of Windows Server 2025
  • Support of Windows 11

Description

Code was updated to be compatible again with Windows platform. Microsoft mandates compilation with Microsoft tools to give support, with that said the code needed to be compatible with Microsoft Visual C++ Compiler for a new version to be built.
Macros we're added to comply with this and change the behavior depending on which platform the project is being built.

Type of change

  • Refactoring
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have confirmed my fix is effective or that my feature works

@vandelvan vandelvan force-pushed the windows branch 4 times, most recently from bafbd71 to 07a2da6 Compare April 18, 2025 23:26
Author:    Author Name vandel_van@hotmail.com
@piste-jp
Copy link
Member

I would like to notify this comment in advance before this PR goes to compilable...

I know you are working so hard on this PR and also I know you want to support windows again in the IBM storage archive product. But I must strongly disagree to this PR. Because this PR has no benefit to the normal open source users who are using the code in this repository. On the other hand code change is big and impact of the readability of codes are really big.

I have so many comments and complains but top-3 of my comments are

First, please don't introduce crossbuild directory easily. This kind of architecture specific code is handled under libltfs/arch directory. Please follow this as much as possible.

Second, please don't use SAFE_ prefix in the macros in commons.h. Frankly I cannot understand what does SAFE_ means. I believe they are "safe" only in windows environment for for Linux/Mac/BSDs env. I don't recommend that we use the C++11/C99 "Annex K" functions because of its history, they are optional and they are not supported in the glibc yet. What is the problem that LTFS uses current ANSI C standard functions on windows env? I strongly recommend that you need arch_ prefix and design glue layer carefully like thread handling in LTFS, see src/libltfs/ltfs_thread.h carefully.

For example, SAFE_FOPEN looks only safe for windows. And SAFE_WRITE cannot be understand what is "safe" at all.

Last, please write macros to keep the C language context. I believe macro feature can easily ruins the C language context and create new your own langage. But this project is clearly written by C please do not corrupt the readability for C developers. I strongly recommend that you need to use inline function as much possible, that is a reason taht we choose C99.

For example, this macro call confuses C developers in short period. They don't think conf_file is output of function (macro) at a glance. Of course, they can understand soon, but that small thinking time reduces the readability totally.

SAFE_FOPEN(path, "rb", conf_file);

Copy link
Member

@piste-jp piste-jp left a comment

Choose a reason for hiding this comment

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

Why do you want to use arch_ prefix for POSIX functions.

I believe your change doesn't make this code compilable on Visual C. This just a part of Visual C compilation only in IBM.

So I believe you need to minimize the code change because there is no benefit to this project at all!

My recommendation is just use POSIX functions as POSIX function name.

Honestly, I cannot understand why you want to replace POSIX function name to name with arch_ prefix. But if it is to suppress the waring message in Visual C, please suppress it with pragma declaration like below.

#ifdef _MSC_VER
#pragma warning(suppress : 4996)
...
#endif

See also, https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-write?view=msvc-170.

Second best is

#ifdef _MSC_VER
#define write _write
...
#endif

#define INVALID_KEY UINT_MAX


#define arch_vsprintf(buffer,bufferCount, fmt, ...) vsprintf_s((buffer), (bufferCount), (fmt), __VA_ARGS__)
Copy link
Member

Choose a reason for hiding this comment

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

Please do not use camel case bufferCount.

This is macro definition, so long variable name is not needed.

Copy link
Member

@piste-jp piste-jp left a comment

Choose a reason for hiding this comment

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

I roughly make comments. They are not everything.

I just at a glance and make comments.

@@ -1764,7 +1764,7 @@ ssize_t _unified_insert_new_request(const char *buf, off_t offset, size_t count,
memcpy(cache_manager_get_object_data(*cache), buf, copy_count);

/* Store new write request */
new_req = calloc(1, sizeof(struct write_request));
new_req = (struct write_request*)calloc(1, sizeof(struct write_request));
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why this cast is needed.

struct timer_info timerinfo;
struct unified_data *priv = iosched_handle;

Copy link
Member

Choose a reason for hiding this comment

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

Do not keep the leading spaces in an empty line.

@@ -2325,7 +2325,7 @@ int unified_set_profiler(char *work_dir, bool enable, void *iosched_handle)
return -LTFS_NO_MEMORY;
}

p = fopen(path, PROFILER_FILE_MODE);
arch_fopen(path, PROFILER_FILE_MODE,p);
Copy link
Member

Choose a reason for hiding this comment

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

why fopen_s() is needed on windows?

strcat((char *) priv.dk_list, (char *) key[i].dk);
strcat((char *) priv.dk_list, ":");
strcat((char *) priv.dk_list, (char *) key[i].dki);
arch_strcat((char *) priv.dk_list, dk_list_len, "/");
Copy link
Member

Choose a reason for hiding this comment

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

I cannot understand why strcat_s() is needed here. Every input string can be handled safely in this function...

If you have a reason please explain it by comment and add strcat_s() function into linux side. I don't like Annex K, but it is better than this, if you have a strong reason.


#define arch_access(filename, mode) _access((filename), (mode))

#define arch_xmlfree(ptr) xmlFree((ptr))
Copy link
Member

Choose a reason for hiding this comment

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

I recommend this.

#define xmlfree xmlFree


#define arch_access(filename, mode) access(filename, mode)

#define arch_xmlfree(ptr) arch_safe_free(ptr)
Copy link
Member

Choose a reason for hiding this comment

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

I recommend that this line is removed.

char rule[len+1], last, *ptr;

char *rule = NULL, last, *ptr;
int ruleLen = (sizeof(char) * (int)(len + 1));
Copy link
Member

Choose a reason for hiding this comment

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

Please do not use camel case.

int ruleLen = (sizeof(char) * (int)(len + 1));
rule = (char*)calloc(ruleLen,sizeof(char));
if (rule == NULL) {
return -LTFS_NO_MEMORY;
Copy link
Member

Choose a reason for hiding this comment

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

Error message is needed.

rulebuf = (char*)malloc(sizeof(char) * (len + 1));
if (rulebuf == NULL)
{
return -LTFS_NO_MEMORY;
Copy link
Member

Choose a reason for hiding this comment

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

Error message is needed.

@piste-jp
Copy link
Member

piste-jp commented May 1, 2025

Hmm, this PR has so many changes but no benefit to the original code users. Because they don't have any code built on windows even if your change is committed.

Let me clarify how to progress.. I strongly recommend that you start over from scratch again.

Objective

Change the code to be built on Visual C for the IBM product. But the tree cannot be built for this project.

Directions

  1. Keep original code as much as possible, minimize changes
  2. Do not make any refactoring and other prettifications
  3. Drop MinGW support (move to Visual C support)

Changes Detail

  1. Use POSIX functions as is (suppress warnings with #pragma as much as possible for windows)
  2. Do not use Annex K functions as little s possible as (suppress warnings with #pragma as much as possible for windows)
  3. Use inline wrapper functions for above if it is really needed

@vandelvan vandelvan removed their request for review May 2, 2025 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants