eal: create a runtime directory on windows
PATCH 1/1 eal: create a runtime directory on windows
Added eal_create_runtime_dir() function in order to run any application as a user that does not have administrator access. Currently, since there is no runtime directory set, the code tries to create a file in C:\ which is only writable with administrator privileges. As a result, if the user is not admin, the application will fail.
--- lib/librte_eal/windows/eal.c | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
lib/librte_eal/windows/eal.c +57 -0
@@ -5,6 +5,7 @@#include <fcntl.h> #include <io.h> #include <share.h> +#include <direct.h> #include <sys/stat.h> #include <rte_debug.h>
@@ -34,6 +35,55 @@ static int mem_cfg_fd = -1;/* internal configuration (per-core) */ struct lcore_config lcore_config[RTE_MAX_LCORE ]; +int +eal_create_runtime_dir (void ) +{ +char temp_dir[PATH_MAX ]; +char runtime_dir[PATH_MAX ]; +int ret; + +/* get user-writable temp path */ +if (GetTempPathA (sizeof (temp_dir), temp_dir) ==0 ) { +RTE_LOG_WIN32_ERR ("GetTempPath" ); +return -1 ; + } + +/* create DPDK runtime subdirectory under temp dir */ + ret =strcat_s (temp_dir,sizeof (temp_dir),"dpdk" ); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL ,"Error creating DPDK runtime path name\n" ); +return -1 ; + } + +/* create prefix-specific subdirectory under DPDK runtime dir */ + ret =snprintf (runtime_dir,sizeof (runtime_dir),"%s\\%s" , + temp_dir,eal_get_hugefile_prefix ()); +if (ret <0 || ret ==sizeof (runtime_dir)) { +RTE_LOG (ERR ,EAL ,"Error creating prefix-specific runtime path\n" ); +return -1 ; + } + +/* create the path if it doesn't exist - step by step */ + ret =_mkdir (temp_dir); +if (ret <0 && errno !=EEXIST ) { +RTE_LOG (ERR ,EAL ,"Error creating '%s': %s\n" , + temp_dir,strerror (errno)); +return -1 ; + } + + ret =_mkdir (runtime_dir); +if (ret <0 && errno !=EEXIST ) { +RTE_LOG (ERR ,EAL ,"Error creating '%s': %s\n" , + runtime_dir,strerror (errno)); +return -1 ; + } + +if (eal_set_runtime_dir (runtime_dir,sizeof (runtime_dir))) +return -1 ; + +return 0 ; +} +/* Detect if we are a primary or a secondary process */ enum rte_proc_type_t eal_proc_type_detect (void )
@@ -181,6 +231,13 @@ eal_parse_args(int argc, char **argv) } } +/* create runtime data directory */ +if (internal_conf->no_shconf ==0 && +eal_create_runtime_dir () <0 ) { +RTE_LOG (ERR ,EAL ,"Cannot create runtime directory\n" ); +return -1 ; + } +if (eal_adjust_config (internal_conf) !=0 )return -1 ;
Signature · 1 line
2.18.0.windows.1
Quoted 85 lines · Pallavi Kadam
Added
eal_create_runtime_dir()function in order to run any application as a user that does not have administrator access. Currently, since there is no runtime directory set, the code tries to create a file in C:\ which is only writable with administrator privileges. As a result, if the user is not admin, the application will fail.Signed-off-by Ranjit Menon <[email protected]>Signed-off-by Pallavi Kadam <[email protected]>--- lib/librte_eal/windows/eal.c | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)lib/librte_eal/windows/eal.c +50
-0@@ -5,6 +5,7 @@#include <fcntl.h> #include <io.h> #include <share.h> +#include <direct.h> #include <sys/stat.h> #include <rte_debug.h> @@ -34,6 +35,55 @@ static int mem_cfg_fd = -1;/* internal configuration (per-core) */ struct lcore_config lcore_config[RTE_MAX_LCORE ]; +int +eal_create_runtime_dir (void ) +{ +char temp_dir[PATH_MAX ]; +char runtime_dir[PATH_MAX ]; +int ret; + +/* get user-writable temp path */ +if (GetTempPathA (sizeof (temp_dir), temp_dir) ==0 ) { +RTE_LOG_WIN32_ERR ("GetTempPath" ); +return -1 ; + } + +/* create DPDK runtime subdirectory under temp dir */ + ret =strcat_s (temp_dir,sizeof (temp_dir),"dpdk" ); +if (ret !=0 ) { +RTE_LOG (ERR ,EAL ,"Error creating DPDK runtime path name\n" ); +return -1 ; + } + +/* create prefix-specific subdirectory under DPDK runtime dir */ + ret =snprintf (runtime_dir,sizeof (runtime_dir),"%s\\%s" , + temp_dir,eal_get_hugefile_prefix ()); +if (ret <0 || ret ==sizeof (runtime_dir)) { +RTE_LOG (ERR ,EAL ,"Error creating prefix-specific runtime path\n" ); +return -1 ; + } + +/* create the path if it doesn't exist - step by step */ + ret =_mkdir (temp_dir); +if (ret <0 && errno !=EEXIST ) { +RTE_LOG (ERR ,EAL ,"Error creating '%s': %s\n" , + temp_dir,strerror (errno)); +return -1 ; + } + + ret =_mkdir (runtime_dir); +if (ret <0 && errno !=EEXIST ) { +RTE_LOG (ERR ,EAL ,"Error creating '%s': %s\n" , + runtime_dir,strerror (errno)); +return -1 ; + } + +if (eal_set_runtime_dir (runtime_dir,sizeof (runtime_dir))) +return -1 ; + +return 0 ; +} +/* Detect if we are a primary or a secondary process */ enum rte_proc_type_t eal_proc_type_detect (void )@@ -181,6 +231,13 @@ eal_parse_args(int argc, char **argv) } }
lib/librte_eal/windows/eal.c eal_parse_args(int argc, char **argv) · line 243
Quoted 10 lines
lib/librte_eal/windows/eal.c +7
-0+/* create runtime data directory */ +if (internal_conf->no_shconf ==0 && +eal_create_runtime_dir () <0 ) { +RTE_LOG (ERR ,EAL ,"Cannot create runtime directory\n" ); +return -1 ; + } +if (eal_adjust_config (internal_conf) !=0 )return -1 ;
Thomas, Dmitry: If at all possible, I think we should try and get this fix into -rc2.
Without this fix, a non-admin user cannot run any application on Windows.
ranjit m.
Quoted 6 lines
/* Detect if we are a primary or a secondary process */ enum
rte_proc_type_teal_proc_type_detect(void)lib/librte_eal/windows/eal.c +0
-0@@ -181,6 +231,13 @@ eal_parse_args(int argc, char **argv) } }
lib/librte_eal/windows/eal.c eal_parse_args(int argc, char **argv) · line 242
Quoted 10 lines
lib/librte_eal/windows/eal.c +7
-0+/* create runtime data directory */ +if (internal_conf->no_shconf ==0 && +eal_create_runtime_dir () <0 ) { +RTE_LOG (ERR ,EAL ,"Cannot create runtime directory\n" ); +return -1 ; + } +if (eal_adjust_config (internal_conf) !=0 )return -1 ;
Windows rte_eal_init() forces in-memory operation (internal_conf.in_memory=0) with a warning message, because runtime directory and shared configuration is only used for multi-process. Maybe do the same for no_shconf, as it's essentially the same, but for legacy mode?
Hi Dmitry,
Quoted 7 lines · Dmitry Kozlyuk
Quoted 7 lines
/* Detect if we are a primary or a secondary process */ enum
rte_proc_type_teal_proc_type_detect(void)(quoted diff) +0
-0@@ -181,6 +231,13 @@ eal_parse_args(int argc, char **argv) } }
Quoted 13 lines
lib/librte_eal/windows/eal.c eal_parse_args(int argc, char **argv) · line 242
Quoted 9 lines
lib/librte_eal/windows/eal.c +7
-0+/* create runtime data directory */ +if (internal_conf->no_shconf ==0 && +eal_create_runtime_dir () <0 ) { +RTE_LOG (ERR ,EAL ,"Cannot create runtime directory\n" ); +return -1 ; + } +if (eal_adjust_config (internal_conf) !=0 )return -1 ;Windows
rte_eal_init()forces in-memory operation (internal_conf.in_memory=0) with a warning message, because runtime directory and shared configuration is only used for multi-process. Maybe do the same forno_shconf, as it's essentially the same, but for legacy mode?
Thank you for the suggestion.
We sent out v2, forcing no_shconf to 1 for now.
PATCH v2 1/1 eal: enable windows apps to run on non-admin users
In reply to Pallavi KadamCurrently, since there is no runtime directory set, the code tries to create a file in C:\ which is only writable with administrator privileges. As a result, if the user is not admin, the application will fail.
So, forcing no_shconf to 1 to prevent the code having to create files in the runtime directory.
--- lib/librte_eal/windows/eal.c | 1 + 1 file changed, 1 insertion(+)
lib/librte_eal/windows/eal.c +1 -0
@@ -295,6 +295,7 @@ rte_eal_init(int argc, char **argv)RTE_LOG (WARNING ,EAL ,"Multi-process support is requested, " "but not available.\n" ); internal_conf->in_memory =1 ; + internal_conf->no_shconf =1 ; }if (!internal_conf->no_hugetlbfs && (eal_hugepage_info_init () <0 )) {
Signature · 1 line
2.18.0.windows.1
Re: [dpdk-dev] [PATCH v2] eal: enable windows apps to run on non-admin users
Quoted 19 lines · Pallavi Kadam
Currently, since there is no runtime directory set, the code tries to create a file in C:\ which is only writable with administrator privileges. As a result, if the user is not admin, the application will fail.
So, forcingno_shconfto 1 to prevent the code having to create files in the runtime directory.Suggested-by Dmitry Kozlyuk <[email protected]>Signed-off-by Pallavi Kadam <[email protected]>Reviewed-by Ranjit Menon <[email protected]>--- lib/librte_eal/windows/eal.c | 1 + 1 file changed, 1 insertion(+)lib/librte_eal/windows/eal.c +0
-0
lib/librte_eal/windows/eal.c rte_eal_init(int argc, char **argv) · line 301
Quoted 7 lines
lib/librte_eal/windows/eal.c +1
-0@@ -295,6 +295,7 @@ rte_eal_init(int argc, char **argv)RTE_LOG (WARNING ,EAL ,"Multi-process support is requested, " "but not available.\n" ); internal_conf->in_memory =1 ; + internal_conf->no_shconf =1 ; }if (!internal_conf->no_hugetlbfs && (eal_hugepage_info_init () <0 )) {
Re: [dpdk-dev] [PATCH v2] eal: enable windows apps to run on non-admin users
In reply to Pallavi KadamQuoted 20 lines · Pallavi Kadam
Currently, since there is no runtime directory set, the code tries to create a file in C:\ which is only writable with administrator privileges. As a result, if the user is not admin, the application will fail.
So, forcingno_shconfto 1 to prevent the code having to create files in the runtime directory.Suggested-by Dmitry Kozlyuk <[email protected]>Signed-off-by Pallavi Kadam <[email protected]>Reviewed-by Ranjit Menon <[email protected]>--- lib/librte_eal/windows/eal.c | 1 + 1 file changed, 1 insertion(+)lib/librte_eal/windows/eal.c +0
-0
lib/librte_eal/windows/eal.c rte_eal_init(int argc, char **argv) · line 301
Quoted 7 lines
lib/librte_eal/windows/eal.c +1
-0@@ -295,6 +295,7 @@ rte_eal_init(int argc, char **argv)RTE_LOG (WARNING ,EAL ,"Multi-process support is requested, " "but not available.\n" ); internal_conf->in_memory =1 ; + internal_conf->no_shconf =1 ; }if (!internal_conf->no_hugetlbfs && (eal_hugepage_info_init () <0 )) {
This is the correct way, as in-memory implies no_shconf. I would like to deprecate noshconf option as it's a subset of what in-memory does.
Signature · 2 lines
Thanks, Anatoly
Thomas Monjalon
AppliedRe: [dpdk-dev] [PATCH v2] eal: enable windows apps to run on non-admin users
28/10/2020 13:41, Burakov, Anatoly:
Quoted 18 lines · Pallavi Kadam
lib/librte_eal/windows/eal.c rte_eal_init(int argc, char **argv) · line 298
Quoted 13 lines
Currently, since there is no runtime directory set, the code tries to create a file in C:\ which is only writable with administrator privileges. As a result, if the user is not admin, the application will fail.
So, forcingno_shconfto 1 to prevent the code having to create files in the runtime directory.Suggested-by Dmitry Kozlyuk <[email protected]>Signed-off-by Pallavi Kadam <[email protected]>Reviewed-by Ranjit Menon <[email protected]>---
internal_conf->in_memory= 1;lib/librte_eal/windows/eal.c +1
-0+ internal_conf->no_shconf =1 ;This is the correct way, as in-memory implies
no_shconf. I would like to deprecate noshconf option as it's a subset of what in-memory does.
Quoted 1 line
Acked-by Anatoly Burakov <[email protected]>
Applied, thanks
Re: [dpdk-dev] [PATCH v2] eal: enable windows apps to run on non-admin users
In reply to Pallavi KadamQuoted 7 lines · Pallavi Kadam
Currently, since there is no runtime directory set, the code tries to create a file in C:\ which is only writable with administrator privileges. As a result, if the user is not admin, the application will fail.
So, forcingno_shconfto 1 to prevent the code having to create files in the runtime directory.
Quoted 7 lines
Suggested-by Dmitry Kozlyuk <[email protected]>Signed-off-by Pallavi Kadam <[email protected]>Reviewed-by Ranjit Menon <[email protected]>--- lib/librte_eal/windows/eal.c | 1 + 1 file changed, 1 insertion(+)