Skip to content

Commit

Permalink
Fixed "opcache.file_cache_fallback" mode.
Browse files Browse the repository at this point in the history
It's not safe to change value of ZCG(accel_directives).file_cache_only, becuse it might be altered by INI subsystem.
Use global variable instead.
  • Loading branch information
dstogov committed Mar 5, 2018
1 parent a827aef commit 350082e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
22 changes: 15 additions & 7 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ zend_accel_shared_globals *accel_shared_globals = NULL;
zend_bool accel_startup_ok = 0;
static char *zps_failure_reason = NULL;
char *zps_api_failure_reason = NULL;
#ifdef HAVE_OPCACHE_FILE_CACHE
zend_bool file_cache_only = 0; /* process uses file cache only */
#endif
#if ENABLE_FILE_CACHE_FALLBACK
zend_bool fallback_process = 0; /* process uses file cache fallback */
#endif
Expand Down Expand Up @@ -448,7 +451,7 @@ zend_string *accel_new_interned_string(zend_string *str)
Bucket *p;

#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache_only) {
if (file_cache_only) {
return str;
}
#endif
Expand Down Expand Up @@ -1700,7 +1703,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
/* The Accelerator is disabled, act as if without the Accelerator */
return accelerator_orig_compile_file(file_handle, type);
#ifdef HAVE_OPCACHE_FILE_CACHE
} else if (ZCG(accel_directives).file_cache_only) {
} else if (file_cache_only) {
return file_cache_compile_file(file_handle, type);
#endif
} else if ((!ZCG(counted) && !ZCSG(accelerator_enabled)) ||
Expand Down Expand Up @@ -1999,6 +2002,9 @@ static int persistent_stream_open_function(const char *filename, zend_file_handl
static zend_string* persistent_zend_resolve_path(const char *filename, int filename_len)
{
if (ZCG(enabled) && accel_startup_ok &&
#ifdef HAVE_OPCACHE_FILE_CACHE
!file_cache_only &&
#endif
(ZCG(counted) || ZCSG(accelerator_enabled)) &&
!ZCSG(restart_in_progress)) {

Expand Down Expand Up @@ -2130,7 +2136,7 @@ static void accel_activate(void)
ZCG(cwd_check) = 1;

#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache_only) {
if (file_cache_only) {
return;
}
#endif
Expand Down Expand Up @@ -2801,7 +2807,8 @@ static int accel_startup(zend_extension *extension)
/* End of non-SHM dependent initializations */
/********************************************/
#ifdef HAVE_OPCACHE_FILE_CACHE
if (!ZCG(accel_directives).file_cache_only) {
file_cache_only = ZCG(accel_directives).file_cache_only;
if (!file_cache_only) {
#else
if (1) {
#endif
Expand Down Expand Up @@ -2839,6 +2846,7 @@ static int accel_startup(zend_extension *extension)
#if ENABLE_FILE_CACHE_FALLBACK
case ALLOC_FALLBACK:
zend_shared_alloc_lock();
file_cache_only = 1;
fallback_process = 1;
zend_accel_init_auto_globals();
zend_shared_alloc_unlock();
Expand Down Expand Up @@ -2937,7 +2945,7 @@ static void accel_free_ts_resources()
void accel_shutdown(void)
{
zend_ini_entry *ini_entry;
zend_bool file_cache_only = 0;
zend_bool _file_cache_only = 0;

zend_optimizer_shutdown();

Expand All @@ -2964,12 +2972,12 @@ void accel_shutdown(void)
zend_interned_strings_restore = orig_interned_strings_restore;

#ifdef HAVE_OPCACHE_FILE_CACHE
file_cache_only = ZCG(accel_directives).file_cache_only;
_file_cache_only = file_cache_only;
#endif

accel_free_ts_resources();

if (!file_cache_only) {
if (!_file_cache_only) {
zend_shared_alloc_shutdown();
}
zend_compile_file = accelerator_orig_compile_file;
Expand Down
5 changes: 5 additions & 0 deletions ext/opcache/ZendAccelerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ extern int lock_file;

#if defined(HAVE_OPCACHE_FILE_CACHE) && defined(ZEND_WIN32)
# define ENABLE_FILE_CACHE_FALLBACK 1
#else
# define ENABLE_FILE_CACHE_FALLBACK 0
#endif

#if ZEND_WIN32
Expand Down Expand Up @@ -284,6 +286,9 @@ typedef struct _zend_accel_shared_globals {
} zend_accel_shared_globals;

extern zend_bool accel_startup_ok;
#ifdef HAVE_OPCACHE_FILE_CACHE
extern zend_bool file_cache_only;
#endif
#if ENABLE_FILE_CACHE_FALLBACK
extern zend_bool fallback_process;
#endif
Expand Down
3 changes: 0 additions & 3 deletions ext/opcache/shared_alloc_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ static int zend_shared_alloc_reattach(size_t requested_size, char **error_in)
}
accel_shared_globals = (zend_accel_shared_globals *)((char *)((zend_smm_shared_globals *)mapping_base)->app_shared_globals + ((char *)mapping_base - (char *)wanted_mb_save));

/* Make this process to use file-cache only */
ZCG(accel_directives).file_cache_only = 1;

return ALLOC_FALLBACK;
}
#endif
Expand Down
10 changes: 5 additions & 5 deletions ext/opcache/zend_accelerator_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ void zend_accel_override_file_functions(void)
zend_function *old_function;
if (ZCG(enabled) && accel_startup_ok && ZCG(accel_directives).file_override_enabled) {
#ifdef HAVE_OPCACHE_FILE_CACHE
if (ZCG(accel_directives).file_cache_only) {
if (file_cache_only) {
zend_accel_error(ACCEL_LOG_WARNING, "file_override_enabled has no effect when file_cache_only is set");
return;
}
Expand Down Expand Up @@ -442,7 +442,7 @@ void zend_accel_info(ZEND_MODULE_INFO_FUNC_ARGS)

if (ZCG(enabled) && accel_startup_ok &&
#ifdef HAVE_OPCACHE_FILE_CACHE
((ZCG(counted) || ZCSG(accelerator_enabled)) || ZCG(accel_directives).file_cache_only)
((ZCG(counted) || ZCSG(accelerator_enabled)) || file_cache_only)
#else
(ZCG(counted) || ZCSG(accelerator_enabled))
#endif
Expand All @@ -457,7 +457,7 @@ void zend_accel_info(ZEND_MODULE_INFO_FUNC_ARGS)
php_info_print_table_row(2, "Optimization", "Disabled");
}
#ifdef HAVE_OPCACHE_FILE_CACHE
if (!ZCG(accel_directives).file_cache_only) {
if (!file_cache_only) {
php_info_print_table_row(2, "SHM Cache", "Enabled");
} else {
php_info_print_table_row(2, "SHM Cache", "Disabled");
Expand All @@ -467,7 +467,7 @@ void zend_accel_info(ZEND_MODULE_INFO_FUNC_ARGS)
} else {
php_info_print_table_row(2, "File Cache", "Disabled");
}
if (ZCG(accel_directives).file_cache_only) {
if (file_cache_only) {
if (!accel_startup_ok || zps_api_failure_reason) {
php_info_print_table_row(2, "Startup Failed", zps_api_failure_reason);
} else {
Expand Down Expand Up @@ -616,7 +616,7 @@ static ZEND_FUNCTION(opcache_get_status)
if (ZCG(accel_directives).file_cache) {
add_assoc_string(return_value, "file_cache", ZCG(accel_directives).file_cache);
}
if (ZCG(accel_directives).file_cache_only) {
if (file_cache_only) {
add_assoc_bool(return_value, "file_cache_only", 1);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/zend_file_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ zend_persistent_script *zend_file_cache_script_load(zend_file_handle *file_handl
return NULL;
}

if (!ZCG(accel_directives).file_cache_only &&
if (!file_cache_only &&
!ZCSG(restart_in_progress) &&
!ZSMMG(memory_exhausted) &&
accelerator_shm_read_lock() == SUCCESS) {
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/zend_persist.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#ifdef HAVE_OPCACHE_FILE_CACHE
#define zend_set_str_gc_flags(str) do { \
if (ZCG(accel_directives).file_cache_only) { \
if (file_cache_only) { \
GC_FLAGS(str) = IS_STR_INTERNED; \
} else { \
GC_FLAGS(str) = IS_STR_INTERNED | IS_STR_PERMANENT; \
Expand Down

0 comments on commit 350082e

Please sign in to comment.